File tree Expand file tree Collapse file tree 2 files changed +16
-11
lines changed Expand file tree Collapse file tree 2 files changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -622,26 +622,31 @@ func SearchRepo(ctx *context.Context) {
622622 }
623623 }
624624
625- var err error
625+ // To improve performance when only the count is requested
626+ if ctx .FormBool ("count_only" ) {
627+ if count , err := repo_model .CountRepository (ctx , opts ); err != nil {
628+ log .Error ("CountRepository: %v" , err )
629+ ctx .JSON (http .StatusInternalServerError , nil ) // frontend JS doesn't handle error response (same as below)
630+ } else {
631+ ctx .SetTotalCountHeader (count )
632+ ctx .JSONOK ()
633+ }
634+ return
635+ }
636+
626637 repos , count , err := repo_model .SearchRepository (ctx , opts )
627638 if err != nil {
628- ctx .JSON (http .StatusInternalServerError , api.SearchError {
629- OK : false ,
630- Error : err .Error (),
631- })
639+ log .Error ("SearchRepository: %v" , err )
640+ ctx .JSON (http .StatusInternalServerError , nil )
632641 return
633642 }
634643
635644 ctx .SetTotalCountHeader (count )
636645
637- // To improve performance when only the count is requested
638- if ctx .FormBool ("count_only" ) {
639- return
640- }
641-
642646 latestCommitStatuses , err := commitstatus_service .FindReposLastestCommitStatuses (ctx , repos )
643647 if err != nil {
644648 log .Error ("FindReposLastestCommitStatuses: %v" , err )
649+ ctx .JSON (http .StatusInternalServerError , nil )
645650 return
646651 }
647652
Original file line number Diff line number Diff line change @@ -235,7 +235,7 @@ const sfc = {
235235 if (! this .reposTotalCount ) {
236236 const totalCountSearchURL = ` ${ this .subUrl } /repo/search?count_only=1&uid=${ this .uid } &team_id=${ this .teamId } &q=&page=1&mode=` ;
237237 response = await GET (totalCountSearchURL);
238- this .reposTotalCount = response .headers .get (' X-Total-Count' );
238+ this .reposTotalCount = response .headers .get (' X-Total-Count' ) ?? ' ? ' ;
239239 }
240240
241241 response = await GET (searchedURL);
You can’t perform that action at this time.
0 commit comments