summaryrefslogtreecommitdiffstats
path: root/models/repo_list.go
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2017-03-11 03:50:12 -0500
committerLunny Xiao <xiaolunwen@gmail.com>2017-03-11 16:50:12 +0800
commitc99e7e1a62788b7bfdda1d3189a2b8c2254efa96 (patch)
tree3fad12ec9082b26b09c22ec29518c9894237266a /models/repo_list.go
parent3803f257fb5cfa3419f0d91ccbae1c128f0fcca1 (diff)
downloadgitea-c99e7e1a62788b7bfdda1d3189a2b8c2254efa96.tar.gz
gitea-c99e7e1a62788b7bfdda1d3189a2b8c2254efa96.zip
Simplify RepositoryList.loadAttributes() (#1211)
Diffstat (limited to 'models/repo_list.go')
-rw-r--r--models/repo_list.go17
1 files changed, 5 insertions, 12 deletions
diff --git a/models/repo_list.go b/models/repo_list.go
index a1a309f9c4..b7e314e707 100644
--- a/models/repo_list.go
+++ b/models/repo_list.go
@@ -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
}