@@ -150,27 +150,57 @@ func getRepoAssignees(ctx context.Context, repo *repo_model.Repository) (_ []*us
150
150
}
151
151
152
152
e := db .GetEngine (ctx )
153
- accesses := make ([]* Access , 0 , 10 )
154
- if err = e .
153
+ userIDs := make ([]int64 , 0 , 10 )
154
+ if err = e .Table ( "access" ).
155
155
Where ("repo_id = ? AND mode >= ?" , repo .ID , perm .AccessModeWrite ).
156
- Find (& accesses ); err != nil {
156
+ Distinct ("id" ).
157
+ Select ("id" ).
158
+ Find (& userIDs ); err != nil {
157
159
return nil , err
158
160
}
159
161
160
- // Leave a seat for owner itself to append later, but if owner is an organization
161
- // and just waste 1 unit is cheaper than re-allocate memory once.
162
- users := make ([]* user_model.User , 0 , len (accesses )+ 1 )
163
- if len (accesses ) > 0 {
164
- userIDs := make ([]int64 , len (accesses ))
165
- for i := 0 ; i < len (accesses ); i ++ {
166
- userIDs [i ] = accesses [i ].UserID
162
+ additionalUserIDs := make ([]int64 , 0 , 10 )
163
+ if err = e .Table ("team_user" ).
164
+ Join ("INNER" , "team_repo" , "`team_repo`.team_id = `team_user`.team_id" ).
165
+ Join ("INNER" , "team_unit" , "`team_unit`.team_id = `team_user`.team_id" ).
166
+ Where ("`team_repo`.repo_id = ? AND `team_unit`.access_mode >= ?" , repo .ID , perm .AccessModeWrite ).
167
+ Distinct ("`team_user`.uid" ).
168
+ Select ("`team_user`.uid" ).
169
+ Find (& additionalUserIDs ); err != nil {
170
+ return nil , err
171
+ }
172
+
173
+ uidMap := map [int64 ]bool {}
174
+ i := 0
175
+ for _ , uid := range userIDs {
176
+ if uidMap [uid ] {
177
+ continue
178
+ }
179
+ uidMap [uid ] = true
180
+ userIDs [i ] = uid
181
+ i ++
182
+ }
183
+ userIDs = userIDs [:i ]
184
+ userIDs = append (userIDs , additionalUserIDs ... )
185
+
186
+ for _ , uid := range additionalUserIDs {
187
+ if uidMap [uid ] {
188
+ continue
167
189
}
190
+ userIDs [i ] = uid
191
+ i ++
192
+ }
193
+ userIDs = userIDs [:i ]
168
194
195
+ // Leave a seat for owner itself to append later, but if owner is an organization
196
+ // and just waste 1 unit is cheaper than re-allocate memory once.
197
+ users := make ([]* user_model.User , 0 , len (userIDs )+ 1 )
198
+ if len (userIDs ) > 0 {
169
199
if err = e .In ("id" , userIDs ).Find (& users ); err != nil {
170
200
return nil , err
171
201
}
172
202
}
173
- if ! repo .Owner .IsOrganization () {
203
+ if ! repo .Owner .IsOrganization () && ! uidMap [ repo . OwnerID ] {
174
204
users = append (users , repo .Owner )
175
205
}
176
206
0 commit comments