Skip to content

Commit 5f7b6b5

Browse files
lunnywxiaoguang
andauthored
Only do counting when count_only=true for repo dashboard (#29884) (#29905)
Ref: #29878 Backport #29884 Co-authored-by: wxiaoguang <[email protected]>
1 parent 408c929 commit 5f7b6b5

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

routers/web/repo/repo.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff 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))

web_src/js/components/DashboardRepoList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)