Skip to content

Commit

Permalink
Simplify RepositoryList.loadAttributes() (#1211)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethantkoenig authored and lunny committed Mar 11, 2017
1 parent 3803f25 commit c99e7e1
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions models/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,19 @@ func (repos RepositoryList) loadAttributes(e Engine) error {
}

// Load owners.
set := make(map[int64]*User)
set := make(map[int64]struct{})
for i := range repos {
set[repos[i].OwnerID] = nil
set[repos[i].OwnerID] = struct{}{}
}
userIDs := make([]int64, 0, len(set))
for userID := range set {
userIDs = append(userIDs, userID)
}
users := make([]*User, 0, len(userIDs))
users := make(map[int64]*User, len(set))
if err := e.
Where("id > 0").
In("id", userIDs).
In("id", keysInt64(set)).
Find(&users); err != nil {
return fmt.Errorf("find users: %v", err)
}
for i := range users {
set[users[i].ID] = users[i]
}
for i := range repos {
repos[i].Owner = set[repos[i].OwnerID]
repos[i].Owner = users[repos[i].OwnerID]
}
return nil
}
Expand Down

0 comments on commit c99e7e1

Please sign in to comment.