mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-23 05:45:34 +03:00
Fix performance regression when user has many organization (#18125)
This commit is contained in:
parent
e0b41f8c37
commit
626b10794f
1 changed files with 18 additions and 12 deletions
|
@ -294,13 +294,27 @@ func CanUserForkRepo(user *user_model.User, repo *repo_model.Repository) (bool,
|
|||
return false, nil
|
||||
}
|
||||
|
||||
// FindUserOrgForks returns the forked repositories for one user from a repository
|
||||
func FindUserOrgForks(repoID, userID int64) ([]*repo_model.Repository, error) {
|
||||
var cond builder.Cond = builder.And(
|
||||
builder.Eq{"fork_id": repoID},
|
||||
builder.In("owner_id",
|
||||
builder.Select("org_id").
|
||||
From("org_user").
|
||||
Where(builder.Eq{"uid": userID}),
|
||||
),
|
||||
)
|
||||
|
||||
var repos []*repo_model.Repository
|
||||
return repos, db.GetEngine(db.DefaultContext).Table("repository").Where(cond).Find(&repos)
|
||||
}
|
||||
|
||||
// GetForksByUserAndOrgs return forked repos of the user and owned orgs
|
||||
func GetForksByUserAndOrgs(user *user_model.User, repo *repo_model.Repository) ([]*repo_model.Repository, error) {
|
||||
var repoList []*repo_model.Repository
|
||||
if user == nil {
|
||||
return repoList, nil
|
||||
}
|
||||
var forkedRepo *repo_model.Repository
|
||||
forkedRepo, err := repo_model.GetUserFork(repo.ID, user.ID)
|
||||
if err != nil {
|
||||
return repoList, err
|
||||
|
@ -308,19 +322,11 @@ func GetForksByUserAndOrgs(user *user_model.User, repo *repo_model.Repository) (
|
|||
if forkedRepo != nil {
|
||||
repoList = append(repoList, forkedRepo)
|
||||
}
|
||||
canCreateRepos, err := GetOrgsCanCreateRepoByUserID(user.ID)
|
||||
orgForks, err := FindUserOrgForks(repo.ID, user.ID)
|
||||
if err != nil {
|
||||
return repoList, err
|
||||
}
|
||||
for _, org := range canCreateRepos {
|
||||
forkedRepo, err := repo_model.GetUserFork(repo.ID, org.ID)
|
||||
if err != nil {
|
||||
return repoList, err
|
||||
}
|
||||
if forkedRepo != nil {
|
||||
repoList = append(repoList, forkedRepo)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
repoList = append(repoList, orgForks...)
|
||||
return repoList, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue