forked from Shiloh/githaven
Only do counting when count_only=true for repo dashboard (#29884)
Ref: #29878
This commit is contained in:
parent
16e360099d
commit
b251e608c0
@ -622,26 +622,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)
|
repos, count, err := repo_model.SearchRepository(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(http.StatusInternalServerError, api.SearchError{
|
log.Error("SearchRepository: %v", err)
|
||||||
OK: false,
|
ctx.JSON(http.StatusInternalServerError, nil)
|
||||||
Error: err.Error(),
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.SetTotalCountHeader(count)
|
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)
|
latestCommitStatuses, err := commitstatus_service.FindReposLastestCommitStatuses(ctx, repos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("FindReposLastestCommitStatuses: %v", err)
|
log.Error("FindReposLastestCommitStatuses: %v", err)
|
||||||
|
ctx.JSON(http.StatusInternalServerError, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ const sfc = {
|
|||||||
if (!this.reposTotalCount) {
|
if (!this.reposTotalCount) {
|
||||||
const totalCountSearchURL = `${this.subUrl}/repo/search?count_only=1&uid=${this.uid}&team_id=${this.teamId}&q=&page=1&mode=`;
|
const totalCountSearchURL = `${this.subUrl}/repo/search?count_only=1&uid=${this.uid}&team_id=${this.teamId}&q=&page=1&mode=`;
|
||||||
response = await GET(totalCountSearchURL);
|
response = await GET(totalCountSearchURL);
|
||||||
this.reposTotalCount = response.headers.get('X-Total-Count');
|
this.reposTotalCount = response.headers.get('X-Total-Count') ?? '?';
|
||||||
}
|
}
|
||||||
|
|
||||||
response = await GET(searchedURL);
|
response = await GET(searchedURL);
|
||||||
|
Loading…
Reference in New Issue
Block a user