@@ -256,29 +256,31 @@ func findTemplateAdmins(ctx context.Context, db database.Store, stats database.G
256
256
return nil , xerrors .Errorf ("unable to fetch template admins: %w" , err )
257
257
}
258
258
259
+ var templateAdmins []database.GetUsersRow
260
+
259
261
usersByIDs := map [uuid.UUID ]database.GetUsersRow {}
262
+ if len (usersByIDs ) == 0 {
263
+ return templateAdmins , nil
264
+ }
265
+
260
266
var userIDs []uuid.UUID
261
267
for _ , user := range users {
262
268
usersByIDs [user .ID ] = user
263
269
userIDs = append (userIDs , user .ID )
264
270
}
265
271
266
- var templateAdmins []database.GetUsersRow
267
- if len (userIDs ) > 0 {
268
- orgIDsByMemberIDs , err := db .GetOrganizationIDsByMemberIDs (ctx , userIDs )
269
- if err != nil {
270
- return nil , xerrors .Errorf ("unable to fetch organization IDs by member IDs: %w" , err )
271
- }
272
+ orgIDsByMemberIDs , err := db .GetOrganizationIDsByMemberIDs (ctx , userIDs )
273
+ if err != nil {
274
+ return nil , xerrors .Errorf ("unable to fetch organization IDs by member IDs: %w" , err )
275
+ }
272
276
273
- for _ , entry := range orgIDsByMemberIDs {
274
- if slices .Contains (entry .OrganizationIDs , stats .TemplateOrganizationID ) {
275
- templateAdmins = append (templateAdmins , usersByIDs [entry .UserID ])
276
- }
277
+ for _ , entry := range orgIDsByMemberIDs {
278
+ if slices .Contains (entry .OrganizationIDs , stats .TemplateOrganizationID ) {
279
+ templateAdmins = append (templateAdmins , usersByIDs [entry .UserID ])
277
280
}
278
281
}
279
282
sort .Slice (templateAdmins , func (i , j int ) bool {
280
283
return templateAdmins [i ].Username < templateAdmins [j ].Username
281
284
})
282
-
283
285
return templateAdmins , nil
284
286
}
0 commit comments