Skip to content

Commit b251e60

Browse files
authored
Only do counting when count_only=true for repo dashboard (#29884)
Ref: #29878
1 parent 16e3600 commit b251e60

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

routers/web/repo/repo.go

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

web_src/js/components/DashboardRepoList.vue

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

0 commit comments

Comments
 (0)