@@ -21,6 +21,7 @@ import (
21
21
"code.gitea.io/gitea/models/unit"
22
22
user_model "code.gitea.io/gitea/models/user"
23
23
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
24
+ db_indexer "code.gitea.io/gitea/modules/indexer/issues/db"
24
25
"code.gitea.io/gitea/modules/log"
25
26
"code.gitea.io/gitea/modules/optional"
26
27
"code.gitea.io/gitea/modules/setting"
@@ -515,7 +516,7 @@ func renderMilestones(ctx *context.Context) {
515
516
ctx .Data ["ClosedMilestones" ] = closedMilestones
516
517
}
517
518
518
- func issues (ctx * context.Context , milestoneID , projectID int64 , isPullOption optional.Option [bool ]) {
519
+ func prepareIssueFilterAndList (ctx * context.Context , milestoneID , projectID int64 , isPullOption optional.Option [bool ]) {
519
520
var err error
520
521
viewType := ctx .FormString ("type" )
521
522
sortType := ctx .FormString ("sort" )
@@ -585,14 +586,17 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
585
586
ctx .Data ["IssueIndexerUnavailable" ] = true
586
587
return
587
588
}
589
+ if len (keywordMatchedIssueIDs ) == 0 {
590
+ // It did search with the keyword, but no issue found, just set issueStats to empty, then no need to do query again.
591
+ issueStats = & issues_model.IssueStats {}
592
+ // set keywordMatchedIssueIDs to empty slice, so we can distinguish it from "nil"
593
+ keywordMatchedIssueIDs = []int64 {}
594
+ }
588
595
statsOpts .IssueIDs = keywordMatchedIssueIDs
589
596
}
590
- if keyword != "" && len (statsOpts .IssueIDs ) == 0 {
591
- // So it did search with the keyword, but no issue found.
592
- // Just set issueStats to empty.
593
- issueStats = & issues_model.IssueStats {}
594
- } else {
595
- // So it did search with the keyword, and found some issues. It needs to get issueStats of these issues.
597
+
598
+ if issueStats == nil {
599
+ // Either it did search with the keyword, and found some issues, it needs to get issueStats of these issues.
596
600
// Or the keyword is empty, so it doesn't need issueIDs as filter, just get issueStats with statsOpts.
597
601
issueStats , err = issues_model .GetIssueStats (ctx , statsOpts )
598
602
if err != nil {
@@ -624,27 +628,21 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
624
628
ctx .Data ["TotalTrackedTime" ] = totalTrackedTime
625
629
}
626
630
627
- page := ctx .FormInt ("page" )
628
- if page <= 1 {
629
- page = 1
630
- }
631
-
632
- var total int
633
- switch {
634
- case isShowClosed .Value ():
635
- total = int (issueStats .ClosedCount )
636
- case ! isShowClosed .Has ():
637
- total = int (issueStats .OpenCount + issueStats .ClosedCount )
638
- default :
639
- total = int (issueStats .OpenCount )
631
+ // prepare pager
632
+ total := int (issueStats .OpenCount + issueStats .ClosedCount )
633
+ if isShowClosed .Value () {
634
+ total = util .Iif (isShowClosed .Value (), int (issueStats .ClosedCount ), int (issueStats .OpenCount ))
640
635
}
636
+ page := max (ctx .FormInt ("page" ), 1 )
641
637
pager := context .NewPagination (total , setting .UI .IssuePagingNum , page , 5 )
642
638
639
+ // prepare real issue list:
643
640
var issues issues_model.IssueList
644
- {
645
- // Do not repeat the keyword search, since if we had any keyword matches we should
646
- // already have their IDs available in keywordMatchedIssueIDs.
647
- ids , err := issueIDsFromSearch (ctx , "" , & issues_model.IssuesOptions {
641
+ if keywordMatchedIssueIDs == nil || len (keywordMatchedIssueIDs ) > 0 {
642
+ // Either it did search with the keyword, and found some issues, then keywordMatchedIssueIDs is not null, it needs to use db indexer.
643
+ // Or the keyword is empty, it also needs to usd db indexer.
644
+ // In either case, no need to use keyword anymore
645
+ searchResult , err := db_indexer .GetIndexer ().Search (ctx , issue_indexer .ToSearchOptions ("" , & issues_model.IssuesOptions {
648
646
Paginator : & db.ListOptions {
649
647
Page : pager .Paginater .Current (),
650
648
PageSize : setting .UI .IssuePagingNum ,
@@ -662,16 +660,13 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
662
660
LabelIDs : labelIDs ,
663
661
SortType : sortType ,
664
662
IssueIDs : keywordMatchedIssueIDs ,
665
- })
663
+ }))
666
664
if err != nil {
667
- if issue_indexer .IsAvailable (ctx ) {
668
- ctx .ServerError ("issueIDsFromSearch" , err )
669
- return
670
- }
671
- ctx .Data ["IssueIndexerUnavailable" ] = true
665
+ ctx .ServerError ("DBIndexer.Search" , err )
672
666
return
673
667
}
674
- issues , err = issues_model .GetIssuesByIDs (ctx , ids , true )
668
+ issueIDs := issue_indexer .SearchResultToIDSlice (searchResult )
669
+ issues , err = issues_model .GetIssuesByIDs (ctx , issueIDs , true )
675
670
if err != nil {
676
671
ctx .ServerError ("GetIssuesByIDs" , err )
677
672
return
@@ -807,7 +802,7 @@ func Issues(ctx *context.Context) {
807
802
ctx .Data ["NewIssueChooseTemplate" ] = issue_service .HasTemplatesOrContactLinks (ctx .Repo .Repository , ctx .Repo .GitRepo )
808
803
}
809
804
810
- issues (ctx , ctx .FormInt64 ("milestone" ), ctx .FormInt64 ("project" ), optional .Some (isPullList ))
805
+ prepareIssueFilterAndList (ctx , ctx .FormInt64 ("milestone" ), ctx .FormInt64 ("project" ), optional .Some (isPullList ))
811
806
if ctx .Written () {
812
807
return
813
808
}
0 commit comments