From 076eaad7430dd80f202446487c99e95e8d803ab3 Mon Sep 17 00:00:00 2001 From: Gusted Date: Tue, 26 Apr 2022 20:34:30 +0000 Subject: Improve dashboard's repo list performance (#18963) * Improve dashboard's repo list performance - Avoid a lot of database lookups for all the repo's, by adding a undocumented "minimal" mode for this specific task, which returns the data that's only needed by this list which doesn't require any database lookups. - Makes fetching these list faster. - Less CPU overhead when a user visits home page. * Refactor javascript code + fix Fork icon - Use async in the function so we can use `await`. - Remove `archivedFilter` check for count, as it doesn't make sense to show the count of repos when you can't even see them(as they are filited away). * Add `count_only` * Remove uncessary code * Improve comment Co-authored-by: delvh * Update web_src/js/components/DashboardRepoList.js Co-authored-by: delvh * Update web_src/js/components/DashboardRepoList.js Co-authored-by: delvh * By default apply minimal mode * Remove `minimal` paramater * Refactor count header * Simplify init Co-authored-by: wxiaoguang Co-authored-by: delvh Co-authored-by: wxiaoguang Co-authored-by: zeripath --- routers/web/repo/repo.go | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'routers/web/repo/repo.go') diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 60298121df..199651b2f1 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -590,26 +590,28 @@ func SearchRepo(ctx *context.Context) { return } + ctx.SetTotalCountHeader(count) + + // To improve performance when only the count is requested + if ctx.FormBool("count_only") { + return + } + results := make([]*api.Repository, len(repos)) for i, repo := range repos { - if err = repo.GetOwner(ctx); err != nil { - ctx.JSON(http.StatusInternalServerError, api.SearchError{ - OK: false, - Error: err.Error(), - }) - return - } - accessMode, err := models.AccessLevel(ctx.Doer, repo) - if err != nil { - ctx.JSON(http.StatusInternalServerError, api.SearchError{ - OK: false, - Error: err.Error(), - }) + results[i] = &api.Repository{ + ID: repo.ID, + FullName: repo.FullName(), + Fork: repo.IsFork, + Private: repo.IsPrivate, + Template: repo.IsTemplate, + Mirror: repo.IsMirror, + Stars: repo.NumStars, + HTMLURL: repo.HTMLURL(), + Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate, } - results[i] = convert.ToRepo(repo, accessMode) } - ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, api.SearchResults{ OK: true, Data: results, -- cgit v1.2.3