diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-03-18 12:05:17 +0100 |
---|---|---|
committer | Earl Warren <contact@earl-warren.org> | 2024-03-26 19:04:25 +0100 |
commit | fbf0b3d661ad81c14546ca25948942f586e2662c (patch) | |
tree | 682bee1769ed5d341be676e963f41c1f4bb65a04 /routers | |
parent | Editor error message misleading due to re-used key. (#29859) (diff) | |
download | forgejo-fbf0b3d661ad81c14546ca25948942f586e2662c.tar.xz forgejo-fbf0b3d661ad81c14546ca25948942f586e2662c.zip |
Only do counting when count_only=true for repo dashboard (#29884)
Ref: #29878
(cherry picked from commit b251e608c01392c947f84be387f956541bfea25c)
Diffstat (limited to 'routers')
-rw-r--r-- | routers/web/repo/repo.go | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 07e6c937b0..bda78b0edc 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -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 } |