aboutsummaryrefslogtreecommitdiffstats
path: root/models/repo/repo_list.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/repo/repo_list.go')
-rw-r--r--models/repo/repo_list.go26
1 files changed, 18 insertions, 8 deletions
diff --git a/models/repo/repo_list.go b/models/repo/repo_list.go
index 1bffadbf0a..9bed2e9197 100644
--- a/models/repo/repo_list.go
+++ b/models/repo/repo_list.go
@@ -98,8 +98,7 @@ func (repos RepositoryList) IDs() []int64 {
return repoIDs
}
-// LoadAttributes loads the attributes for the given RepositoryList
-func (repos RepositoryList) LoadAttributes(ctx context.Context) error {
+func (repos RepositoryList) LoadOwners(ctx context.Context) error {
if len(repos) == 0 {
return nil
}
@@ -107,10 +106,6 @@ func (repos RepositoryList) LoadAttributes(ctx context.Context) error {
userIDs := container.FilterSlice(repos, func(repo *Repository) (int64, bool) {
return repo.OwnerID, true
})
- repoIDs := make([]int64, len(repos))
- for i := range repos {
- repoIDs[i] = repos[i].ID
- }
// Load owners.
users := make(map[int64]*user_model.User, len(userIDs))
@@ -123,12 +118,19 @@ func (repos RepositoryList) LoadAttributes(ctx context.Context) error {
for i := range repos {
repos[i].Owner = users[repos[i].OwnerID]
}
+ return nil
+}
+
+func (repos RepositoryList) LoadLanguageStats(ctx context.Context) error {
+ if len(repos) == 0 {
+ return nil
+ }
// Load primary language.
stats := make(LanguageStatList, 0, len(repos))
if err := db.GetEngine(ctx).
Where("`is_primary` = ? AND `language` != ?", true, "other").
- In("`repo_id`", repoIDs).
+ In("`repo_id`", repos.IDs()).
Find(&stats); err != nil {
return fmt.Errorf("find primary languages: %w", err)
}
@@ -141,10 +143,18 @@ func (repos RepositoryList) LoadAttributes(ctx context.Context) error {
}
}
}
-
return nil
}
+// LoadAttributes loads the attributes for the given RepositoryList
+func (repos RepositoryList) LoadAttributes(ctx context.Context) error {
+ if err := repos.LoadOwners(ctx); err != nil {
+ return err
+ }
+
+ return repos.LoadLanguageStats(ctx)
+}
+
// SearchRepoOptions holds the search options
type SearchRepoOptions struct {
db.ListOptions