aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-03-18 19:05:17 +0800
committerGitHub <noreply@github.com>2024-03-18 11:05:17 +0000
commitb251e608c01392c947f84be387f956541bfea25c (patch)
tree96d225045e0bb04d6f609cddf24441033c667016 /routers
parent16e360099d0a515d429538ec88cff1f3ede23fb4 (diff)
downloadgitea-b251e608c01392c947f84be387f956541bfea25c.tar.gz
gitea-b251e608c01392c947f84be387f956541bfea25c.zip
Only do counting when count_only=true for repo dashboard (#29884)
Ref: #29878
Diffstat (limited to 'routers')
-rw-r--r--routers/web/repo/repo.go25
1 files changed, 15 insertions, 10 deletions
diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go
index 7a626a7065..7f9bf3210a 100644
--- a/routers/web/repo/repo.go
+++ b/routers/web/repo/repo.go
@@ -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)
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
}