1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-24 08:57:03 -05:00

Merge pull request '[v7.0/forgejo] Fix SQL command with too many placeholders' (#3578) from bp-v7.0/forgejo-33cd844-0d029eb into v7.0/forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3578
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2024-05-01 06:50:49 +00:00
commit 6069fcced6
4 changed files with 16 additions and 0 deletions

View file

@ -120,6 +120,9 @@ func FindBranchNames(ctx context.Context, opts FindBranchOptions) ([]string, err
} }
func FindBranchesByRepoAndBranchName(ctx context.Context, repoBranches map[int64]string) (map[int64]string, error) { func FindBranchesByRepoAndBranchName(ctx context.Context, repoBranches map[int64]string) (map[int64]string, error) {
if len(repoBranches) == 0 {
return nil, nil
}
cond := builder.NewCond() cond := builder.NewCond()
for repoID, branchName := range repoBranches { for repoID, branchName := range repoBranches {
cond = cond.Or(builder.And(builder.Eq{"repo_id": repoID}, builder.Eq{"name": branchName})) cond = cond.Or(builder.And(builder.Eq{"repo_id": repoID}, builder.Eq{"name": branchName}))

View file

@ -183,3 +183,12 @@ func TestOnlyGetDeletedBranchOnCorrectRepo(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, deletedBranch) assert.NotNil(t, deletedBranch)
} }
func TestFindBranchesByRepoAndBranchName(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
// With no repos or branches given, we find no branches.
branches, err := git_model.FindBranchesByRepoAndBranchName(db.DefaultContext, map[int64]string{})
assert.NoError(t, err)
assert.Len(t, branches, 0)
}

View file

@ -0,0 +1 @@
Fixed an issue that resulted in excessive and unnecessary database queries when a user with no repositories was viewing their dashboard.

View file

@ -120,6 +120,9 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato
// FindReposLastestCommitStatuses loading repository default branch latest combinded commit status with cache // FindReposLastestCommitStatuses loading repository default branch latest combinded commit status with cache
func FindReposLastestCommitStatuses(ctx context.Context, repos []*repo_model.Repository) ([]*git_model.CommitStatus, error) { func FindReposLastestCommitStatuses(ctx context.Context, repos []*repo_model.Repository) ([]*git_model.CommitStatus, error) {
if len(repos) == 0 {
return nil, nil
}
results := make([]*git_model.CommitStatus, len(repos)) results := make([]*git_model.CommitStatus, len(repos))
for i, repo := range repos { for i, repo := range repos {
if cv := getCommitStatusCache(repo.ID, repo.DefaultBranch); cv != nil { if cv := getCommitStatusCache(repo.ID, repo.DefaultBranch); cv != nil {