Only do counting when count_only=true for repo dashboard (#29884)

Ref: #29878
(cherry picked from commit b251e608c01392c947f84be387f956541bfea25c)
This commit is contained in:
wxiaoguang 2024-03-18 19:05:17 +08:00 committed by Earl Warren
parent 0d3ddec26c
commit fbf0b3d661
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 0579CB2928A78A00
2 changed files with 16 additions and 11 deletions

View file

@ -618,26 +618,31 @@ func SearchRepo(ctx *context.Context) {
}
}
var err error
// To improve performance when only the count is requested
if ctx.FormBool("count_only") {
if count, err := repo_model.CountRepository(ctx, opts); err != nil {
log.Error("CountRepository: %v", err)
ctx.JSON(http.StatusInternalServerError, nil) // frontend JS doesn't handle error response (same as below)
} else {
ctx.SetTotalCountHeader(count)
ctx.JSONOK()
}
return
}
repos, count, err := repo_model.SearchRepository(ctx, opts)
if err != nil {
ctx.JSON(http.StatusInternalServerError, api.SearchError{
OK: false,
Error: err.Error(),
})
log.Error("SearchRepository: %v", err)
ctx.JSON(http.StatusInternalServerError, nil)
return
}
ctx.SetTotalCountHeader(count)
// To improve performance when only the count is requested
if ctx.FormBool("count_only") {
return
}
latestCommitStatuses, err := commitstatus_service.FindReposLastestCommitStatuses(ctx, repos)
if err != nil {
log.Error("FindReposLastestCommitStatuses: %v", err)
ctx.JSON(http.StatusInternalServerError, nil)
return
}

View file

@ -235,7 +235,7 @@ const sfc = {
if (!this.reposTotalCount) {
const totalCountSearchURL = `${this.subUrl}/repo/search?count_only=1&uid=${this.uid}&team_id=${this.teamId}&q=&page=1&mode=`;
response = await GET(totalCountSearchURL);
this.reposTotalCount = response.headers.get('X-Total-Count');
this.reposTotalCount = response.headers.get('X-Total-Count') ?? '?';
}
response = await GET(searchedURL);