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) {
575575 }
576576 }
577577
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+
579590 repos , count , err := repo_model .SearchRepository (ctx , opts )
580591 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 )
585594 return
586595 }
587596
588597 ctx .SetTotalCountHeader (count )
589598
590- // To improve performance when only the count is requested
591- if ctx .FormBool ("count_only" ) {
592- return
593- }
594-
595599 // collect the latest commit of each repo
596600 // at most there are dozens of repos (limited by MaxResponseItems), so it's not a big problem at the moment
597601 repoBranchNames := make (map [int64 ]string , len (repos ))
Original file line number Diff line number Diff line change @@ -236,7 +236,7 @@ const sfc = {
236236 if (! this .reposTotalCount ) {
237237 const totalCountSearchURL = ` ${ this .subUrl } /repo/search?count_only=1&uid=${ this .uid } &team_id=${ this .teamId } &q=&page=1&mode=` ;
238238 response = await GET (totalCountSearchURL);
239- this .reposTotalCount = response .headers .get (' X-Total-Count' );
239+ this .reposTotalCount = response .headers .get (' X-Total-Count' ) ?? ' ? ' ;
240240 }
241241
242242 response = await GET (searchedURL);
You can’t perform that action at this time.
0 commit comments