@@ -150,27 +150,56 @@ func getRepoAssignees(ctx context.Context, repo *repo_model.Repository) (_ []*us
150150 }
151151
152152 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" ).
155155 Where ("repo_id = ? AND mode >= ?" , repo .ID , perm .AccessModeWrite ).
156- Find (& accesses ); err != nil {
156+ Select ("id" ).
157+ Find (& userIDs ); err != nil {
157158 return nil , err
158159 }
159160
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
161+ additionalUserIDs := make ([]int64 , 0 , 10 )
162+ if err = e .Table ("team_user" ).
163+ Join ("INNER" , "team_repo" , "`team_repo`.team_id = `team_user`.team_id" ).
164+ Join ("INNER" , "team_unit" , "`team_unit`.team_id = `team_user`.team_id" ).
165+ Where ("`team_repo`.repo_id = ? AND `team_unit`.access_mode >= ?" , repo .ID , perm .AccessModeWrite ).
166+ Distinct ("`team_user`.uid" ).
167+ Select ("`team_user`.uid" ).
168+ Find (& additionalUserIDs ); err != nil {
169+ return nil , err
170+ }
171+
172+ uidMap := map [int64 ]bool {}
173+ i := 0
174+ for _ , uid := range userIDs {
175+ if uidMap [uid ] {
176+ continue
177+ }
178+ uidMap [uid ] = true
179+ userIDs [i ] = uid
180+ i ++
181+ }
182+ userIDs = userIDs [:i ]
183+ userIDs = append (userIDs , additionalUserIDs ... )
184+
185+ for _ , uid := range additionalUserIDs {
186+ if uidMap [uid ] {
187+ continue
167188 }
189+ userIDs [i ] = uid
190+ i ++
191+ }
192+ userIDs = userIDs [:i ]
168193
194+ // Leave a seat for owner itself to append later, but if owner is an organization
195+ // and just waste 1 unit is cheaper than re-allocate memory once.
196+ users := make ([]* user_model.User , 0 , len (userIDs )+ 1 )
197+ if len (userIDs ) > 0 {
169198 if err = e .In ("id" , userIDs ).Find (& users ); err != nil {
170199 return nil , err
171200 }
172201 }
173- if ! repo .Owner .IsOrganization () {
202+ if ! repo .Owner .IsOrganization () && ! uidMap [ repo . OwnerID ] {
174203 users = append (users , repo .Owner )
175204 }
176205
0 commit comments