Skip to content

Commit 830fcc2

Browse files
Merge branch 'release/v1.23' into go-dep-bump-1.23
2 parents dae2764 + e3021fa commit 830fcc2

File tree

4 files changed

+86
-44
lines changed

4 files changed

+86
-44
lines changed

models/activities/action.go

+19-11
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,24 @@ func ActivityReadable(user, doer *user_model.User) bool {
454454
doer != nil && (doer.IsAdmin || user.ID == doer.ID)
455455
}
456456

457+
func FeedDateCond(opts GetFeedsOptions) builder.Cond {
458+
cond := builder.NewCond()
459+
if opts.Date == "" {
460+
return cond
461+
}
462+
463+
dateLow, err := time.ParseInLocation("2006-01-02", opts.Date, setting.DefaultUILocation)
464+
if err != nil {
465+
log.Warn("Unable to parse %s, filter not applied: %v", opts.Date, err)
466+
} else {
467+
dateHigh := dateLow.Add(86399000000000) // 23h59m59s
468+
469+
cond = cond.And(builder.Gte{"`action`.created_unix": dateLow.Unix()})
470+
cond = cond.And(builder.Lte{"`action`.created_unix": dateHigh.Unix()})
471+
}
472+
return cond
473+
}
474+
457475
func ActivityQueryCondition(ctx context.Context, opts GetFeedsOptions) (builder.Cond, error) {
458476
cond := builder.NewCond()
459477

@@ -534,17 +552,7 @@ func ActivityQueryCondition(ctx context.Context, opts GetFeedsOptions) (builder.
534552
cond = cond.And(builder.Eq{"is_deleted": false})
535553
}
536554

537-
if opts.Date != "" {
538-
dateLow, err := time.ParseInLocation("2006-01-02", opts.Date, setting.DefaultUILocation)
539-
if err != nil {
540-
log.Warn("Unable to parse %s, filter not applied: %v", opts.Date, err)
541-
} else {
542-
dateHigh := dateLow.Add(86399000000000) // 23h59m59s
543-
544-
cond = cond.And(builder.Gte{"`action`.created_unix": dateLow.Unix()})
545-
cond = cond.And(builder.Lte{"`action`.created_unix": dateHigh.Unix()})
546-
}
547-
}
555+
cond = cond.And(FeedDateCond(opts))
548556

549557
return cond, nil
550558
}

models/activities/action_list.go

+25-3
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,31 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
208208
return nil, 0, fmt.Errorf("need at least one of these filters: RequestedUser, RequestedTeam, RequestedRepo")
209209
}
210210

211-
cond, err := ActivityQueryCondition(ctx, opts)
212-
if err != nil {
213-
return nil, 0, err
211+
var err error
212+
var cond builder.Cond
213+
// if the actor is the requested user or is an administrator, we can skip the ActivityQueryCondition
214+
if opts.Actor != nil && opts.RequestedUser != nil && (opts.Actor.IsAdmin || opts.Actor.ID == opts.RequestedUser.ID) {
215+
cond = builder.Eq{
216+
"user_id": opts.RequestedUser.ID,
217+
}.And(
218+
FeedDateCond(opts),
219+
)
220+
221+
if !opts.IncludeDeleted {
222+
cond = cond.And(builder.Eq{"is_deleted": false})
223+
}
224+
225+
if !opts.IncludePrivate {
226+
cond = cond.And(builder.Eq{"is_private": false})
227+
}
228+
if opts.OnlyPerformedBy {
229+
cond = cond.And(builder.Eq{"act_user_id": opts.RequestedUser.ID})
230+
}
231+
} else {
232+
cond, err = ActivityQueryCondition(ctx, opts)
233+
if err != nil {
234+
return nil, 0, err
235+
}
214236
}
215237

216238
actions := make([]*Action, 0, opts.PageSize)

modules/indexer/code/bleve/bleve.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int
266266
pathQuery.FieldVal = "Filename"
267267
pathQuery.SetBoost(10)
268268

269-
contentQuery := bleve.NewMatchQuery(opts.Keyword)
269+
contentQuery := bleve.NewMatchPhraseQuery(opts.Keyword)
270270
contentQuery.FieldVal = "Content"
271271

272272
if opts.IsKeywordFuzzy {

modules/indexer/code/indexer_test.go

+41-29
Original file line numberDiff line numberDiff line change
@@ -165,35 +165,6 @@ func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
165165
},
166166
},
167167
},
168-
// Search for matches on the contents of files within the repo '62'.
169-
// This scenario yields two results (both are based on contents, the first one is an exact match where as the second is a 'fuzzy' one)
170-
{
171-
RepoIDs: []int64{62},
172-
Keyword: "This is not cheese",
173-
Langs: 1,
174-
Results: []codeSearchResult{
175-
{
176-
Filename: "potato/ham.md",
177-
Content: "This is not cheese",
178-
},
179-
{
180-
Filename: "ham.md",
181-
Content: "This is also not cheese",
182-
},
183-
},
184-
},
185-
// Search for matches on the contents of files regardless of case.
186-
{
187-
RepoIDs: nil,
188-
Keyword: "dESCRIPTION",
189-
Langs: 1,
190-
Results: []codeSearchResult{
191-
{
192-
Filename: "README.md",
193-
Content: "# repo1\n\nDescription for repo1",
194-
},
195-
},
196-
},
197168
// Search for an exact match on the filename within the repo '62' (case insenstive).
198169
// This scenario yields a single result (the file avocado.md on the repo '62')
199170
{
@@ -233,6 +204,47 @@ func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
233204
},
234205
}
235206

207+
if name == "elastic_search" {
208+
// Additional scenarios for elastic_search only
209+
additional := []struct {
210+
RepoIDs []int64
211+
Keyword string
212+
Langs int
213+
Results []codeSearchResult
214+
}{
215+
// Search for matches on the contents of files within the repo '62'.
216+
// This scenario yields two results (both are based on contents, the first one is an exact match where as the second is a 'fuzzy' one)
217+
{
218+
RepoIDs: []int64{62},
219+
Keyword: "This is not cheese",
220+
Langs: 1,
221+
Results: []codeSearchResult{
222+
{
223+
Filename: "potato/ham.md",
224+
Content: "This is not cheese",
225+
},
226+
{
227+
Filename: "ham.md",
228+
Content: "This is also not cheese",
229+
},
230+
},
231+
},
232+
// Search for matches on the contents of files regardless of case.
233+
{
234+
RepoIDs: nil,
235+
Keyword: "dESCRIPTION",
236+
Langs: 1,
237+
Results: []codeSearchResult{
238+
{
239+
Filename: "README.md",
240+
Content: "# repo1\n\nDescription for repo1",
241+
},
242+
},
243+
},
244+
}
245+
keywords = append(keywords, additional...)
246+
}
247+
236248
for _, kw := range keywords {
237249
t.Run(kw.Keyword, func(t *testing.T) {
238250
total, res, langs, err := indexer.Search(context.TODO(), &internal.SearchOptions{

0 commit comments

Comments
 (0)