File tree Expand file tree Collapse file tree 2 files changed +15
-11
lines changed Expand file tree Collapse file tree 2 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -575,23 +575,27 @@ func SearchRepo(ctx *context.Context) {
575
575
}
576
576
}
577
577
578
- var err error
578
+ // To improve performance when only the count is requested
579
+ if ctx .FormBool ("count_only" ) {
580
+ if count , err := repo_model .CountRepository (ctx , opts ); err != nil {
581
+ log .Error ("CountRepository: %v" , err )
582
+ ctx .JSON (http .StatusInternalServerError , nil ) // frontend JS doesn't handle error response (same as below)
583
+ } else {
584
+ ctx .SetTotalCountHeader (count )
585
+ ctx .JSONOK ()
586
+ }
587
+ return
588
+ }
589
+
579
590
repos , count , err := repo_model .SearchRepository (ctx , opts )
580
591
if err != nil {
581
- ctx .JSON (http .StatusInternalServerError , api.SearchError {
582
- OK : false ,
583
- Error : err .Error (),
584
- })
592
+ log .Error ("SearchRepository: %v" , err )
593
+ ctx .JSON (http .StatusInternalServerError , nil )
585
594
return
586
595
}
587
596
588
597
ctx .SetTotalCountHeader (count )
589
598
590
- // To improve performance when only the count is requested
591
- if ctx .FormBool ("count_only" ) {
592
- return
593
- }
594
-
595
599
// collect the latest commit of each repo
596
600
// at most there are dozens of repos (limited by MaxResponseItems), so it's not a big problem at the moment
597
601
repoBranchNames := make (map [int64 ]string , len (repos ))
Original file line number Diff line number Diff line change @@ -236,7 +236,7 @@ const sfc = {
236
236
if (! this .reposTotalCount ) {
237
237
const totalCountSearchURL = ` ${ this .subUrl } /repo/search?count_only=1&uid=${ this .uid } &team_id=${ this .teamId } &q=&page=1&mode=` ;
238
238
response = await GET (totalCountSearchURL);
239
- this .reposTotalCount = response .headers .get (' X-Total-Count' );
239
+ this .reposTotalCount = response .headers .get (' X-Total-Count' ) ?? ' ? ' ;
240
240
}
241
241
242
242
response = await GET (searchedURL);
You can’t perform that action at this time.
0 commit comments