]> source.dussan.org Git - gitea.git/commitdiff
Only query team tables if repository is under org when getting assignees (#32414)
authorLunny Xiao <xiaolunwen@gmail.com>
Tue, 5 Nov 2024 07:13:52 +0000 (23:13 -0800)
committerGitHub <noreply@github.com>
Tue, 5 Nov 2024 07:13:52 +0000 (07:13 +0000)
It's unnecessary to query the team table if the repository is not under
organization when getting assignees.

models/repo/user_repo.go

index c305603e02070aad6cac6045aa1022f2bbeb3ff5..ecc9216950738109d07d117f1e6f0703e7823de4 100644 (file)
@@ -110,26 +110,28 @@ func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.Us
                return nil, err
        }
 
-       additionalUserIDs := make([]int64, 0, 10)
-       if err = e.Table("team_user").
-               Join("INNER", "team_repo", "`team_repo`.team_id = `team_user`.team_id").
-               Join("INNER", "team_unit", "`team_unit`.team_id = `team_user`.team_id").
-               Where("`team_repo`.repo_id = ? AND (`team_unit`.access_mode >= ? OR (`team_unit`.access_mode = ? AND `team_unit`.`type` = ?))",
-                       repo.ID, perm.AccessModeWrite, perm.AccessModeRead, unit.TypePullRequests).
-               Distinct("`team_user`.uid").
-               Select("`team_user`.uid").
-               Find(&additionalUserIDs); err != nil {
-               return nil, err
-       }
-
        uniqueUserIDs := make(container.Set[int64])
        uniqueUserIDs.AddMultiple(userIDs...)
-       uniqueUserIDs.AddMultiple(additionalUserIDs...)
+
+       if repo.Owner.IsOrganization() {
+               additionalUserIDs := make([]int64, 0, 10)
+               if err = e.Table("team_user").
+                       Join("INNER", "team_repo", "`team_repo`.team_id = `team_user`.team_id").
+                       Join("INNER", "team_unit", "`team_unit`.team_id = `team_user`.team_id").
+                       Where("`team_repo`.repo_id = ? AND (`team_unit`.access_mode >= ? OR (`team_unit`.access_mode = ? AND `team_unit`.`type` = ?))",
+                               repo.ID, perm.AccessModeWrite, perm.AccessModeRead, unit.TypePullRequests).
+                       Distinct("`team_user`.uid").
+                       Select("`team_user`.uid").
+                       Find(&additionalUserIDs); err != nil {
+                       return nil, err
+               }
+               uniqueUserIDs.AddMultiple(additionalUserIDs...)
+       }
 
        // Leave a seat for owner itself to append later, but if owner is an organization
        // and just waste 1 unit is cheaper than re-allocate memory once.
        users := make([]*user_model.User, 0, len(uniqueUserIDs)+1)
-       if len(userIDs) > 0 {
+       if len(uniqueUserIDs) > 0 {
                if err = e.In("id", uniqueUserIDs.Values()).
                        Where(builder.Eq{"`user`.is_active": true}).
                        OrderBy(user_model.GetOrderByName()).