Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the parallelizing when loading repo for dashboard #24705

Merged
merged 5 commits into from
May 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions routers/web/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"net/http"
"strings"
"sync"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
Expand Down Expand Up @@ -579,20 +578,15 @@ func SearchRepo(ctx *context.Context) {
}

// collect the latest commit of each repo
repoIDsToLatestCommitSHAs := make(map[int64]string)
wg := sync.WaitGroup{}
wg.Add(len(repos))
// at most there are dozens of repos (limited by MaxResponseItems), so it's not a big problem at the moment
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(which is limited by RepoPagingNum)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure?

The PageSize comes from PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),, and ToCorrectPageSize says:

else if size > setting.API.MaxResponseItems {
		size = setting.API.MaxResponseItems
	}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, limit is RepoPagingNum but this condition overrides it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Luckily it's checked, that's what I have double-checked.

Otherwise, attackers could to "limit=99999" to DoS the server.

repoIDsToLatestCommitSHAs := make(map[int64]string, len(repos))
for _, repo := range repos {
go func(repo *repo_model.Repository) {
defer wg.Done()
commitID, err := repo_service.GetBranchCommitID(ctx, repo, repo.DefaultBranch)
if err != nil {
return
}
repoIDsToLatestCommitSHAs[repo.ID] = commitID
}(repo)
commitID, err := repo_service.GetBranchCommitID(ctx, repo, repo.DefaultBranch)
if err != nil {
continue
}
repoIDsToLatestCommitSHAs[repo.ID] = commitID
}
wg.Wait()

// call the database O(1) times to get the commit statuses for all repos
repoToItsLatestCommitStatuses, err := git_model.GetLatestCommitStatusForPairs(ctx, repoIDsToLatestCommitSHAs, db.ListOptions{})
Expand Down