Skip to content

Commit 3b8ce54

Browse files
committed
Only query team tables if repo is under org when getting assignees
1 parent f2a6df0 commit 3b8ce54

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

models/repo/user_repo.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,23 @@ func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.Us
110110
return nil, err
111111
}
112112

113-
additionalUserIDs := make([]int64, 0, 10)
114-
if err = e.Table("team_user").
115-
Join("INNER", "team_repo", "`team_repo`.team_id = `team_user`.team_id").
116-
Join("INNER", "team_unit", "`team_unit`.team_id = `team_user`.team_id").
117-
Where("`team_repo`.repo_id = ? AND (`team_unit`.access_mode >= ? OR (`team_unit`.access_mode = ? AND `team_unit`.`type` = ?))",
118-
repo.ID, perm.AccessModeWrite, perm.AccessModeRead, unit.TypePullRequests).
119-
Distinct("`team_user`.uid").
120-
Select("`team_user`.uid").
121-
Find(&additionalUserIDs); err != nil {
122-
return nil, err
123-
}
124-
125113
uniqueUserIDs := make(container.Set[int64])
126114
uniqueUserIDs.AddMultiple(userIDs...)
127-
uniqueUserIDs.AddMultiple(additionalUserIDs...)
115+
116+
if repo.Owner.IsOrganization() {
117+
additionalUserIDs := make([]int64, 0, 10)
118+
if err = e.Table("team_user").
119+
Join("INNER", "team_repo", "`team_repo`.team_id = `team_user`.team_id").
120+
Join("INNER", "team_unit", "`team_unit`.team_id = `team_user`.team_id").
121+
Where("`team_repo`.repo_id = ? AND (`team_unit`.access_mode >= ? OR (`team_unit`.access_mode = ? AND `team_unit`.`type` = ?))",
122+
repo.ID, perm.AccessModeWrite, perm.AccessModeRead, unit.TypePullRequests).
123+
Distinct("`team_user`.uid").
124+
Select("`team_user`.uid").
125+
Find(&additionalUserIDs); err != nil {
126+
return nil, err
127+
}
128+
uniqueUserIDs.AddMultiple(additionalUserIDs...)
129+
}
128130

129131
// Leave a seat for owner itself to append later, but if owner is an organization
130132
// and just waste 1 unit is cheaper than re-allocate memory once.

0 commit comments

Comments
 (0)