summaryrefslogtreecommitdiffstats
path: root/models/action_list.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2022-03-13 17:40:47 +0100
committerGitHub <noreply@github.com>2022-03-13 17:40:47 +0100
commitbc0d2c8ada14eae81542f30a81552ed5cef8bd5d (patch)
tree5242a9e288f53cfc04e56df495a048d02a902d91 /models/action_list.go
parent780cf76f6e930b5e92fd12ae1e729c5702e70afa (diff)
downloadgitea-bc0d2c8ada14eae81542f30a81552ed5cef8bd5d.tar.gz
gitea-bc0d2c8ada14eae81542f30a81552ed5cef8bd5d.zip
RSS/Atom support for Repos (#19055)
* support for repos * refactor * advertise the feeds via meta tags * allow feed suffix and feed header * optimize performance
Diffstat (limited to 'models/action_list.go')
-rw-r--r--models/action_list.go63
1 files changed, 35 insertions, 28 deletions
diff --git a/models/action_list.go b/models/action_list.go
index 3f52d3cd5e..ce621753a4 100644
--- a/models/action_list.go
+++ b/models/action_list.go
@@ -25,7 +25,7 @@ func (actions ActionList) getUserIDs() []int64 {
return keysInt64(userIDs)
}
-func (actions ActionList) loadUsers(e db.Engine) ([]*user_model.User, error) {
+func (actions ActionList) loadUsers(e db.Engine) (map[int64]*user_model.User, error) {
if len(actions) == 0 {
return nil, nil
}
@@ -42,12 +42,7 @@ func (actions ActionList) loadUsers(e db.Engine) ([]*user_model.User, error) {
for _, action := range actions {
action.ActUser = userMaps[action.ActUserID]
}
- return valuesUser(userMaps), nil
-}
-
-// LoadUsers loads actions' all users
-func (actions ActionList) LoadUsers() ([]*user_model.User, error) {
- return actions.loadUsers(db.GetEngine(db.DefaultContext))
+ return userMaps, nil
}
func (actions ActionList) getRepoIDs() []int64 {
@@ -60,45 +55,57 @@ func (actions ActionList) getRepoIDs() []int64 {
return keysInt64(repoIDs)
}
-func (actions ActionList) loadRepositories(e db.Engine) ([]*repo_model.Repository, error) {
+func (actions ActionList) loadRepositories(e db.Engine) error {
if len(actions) == 0 {
- return nil, nil
+ return nil
}
repoIDs := actions.getRepoIDs()
repoMaps := make(map[int64]*repo_model.Repository, len(repoIDs))
- err := e.
- In("id", repoIDs).
- Find(&repoMaps)
+ err := e.In("id", repoIDs).Find(&repoMaps)
if err != nil {
- return nil, fmt.Errorf("find repository: %v", err)
+ return fmt.Errorf("find repository: %v", err)
}
for _, action := range actions {
action.Repo = repoMaps[action.RepoID]
}
- return valuesRepository(repoMaps), nil
-}
-
-// LoadRepositories loads actions' all repositories
-func (actions ActionList) LoadRepositories() ([]*repo_model.Repository, error) {
- return actions.loadRepositories(db.GetEngine(db.DefaultContext))
+ return nil
}
-// loadAttributes loads all attributes
-func (actions ActionList) loadAttributes(e db.Engine) (err error) {
- if _, err = actions.loadUsers(e); err != nil {
- return
+func (actions ActionList) loadRepoOwner(e db.Engine, userMap map[int64]*user_model.User) (err error) {
+ if userMap == nil {
+ userMap = make(map[int64]*user_model.User)
}
- if _, err = actions.loadRepositories(e); err != nil {
- return
+ for _, action := range actions {
+ repoOwner, ok := userMap[action.Repo.OwnerID]
+ if !ok {
+ repoOwner, err = user_model.GetUserByID(action.Repo.OwnerID)
+ if err != nil {
+ if user_model.IsErrUserNotExist(err) {
+ continue
+ }
+ return err
+ }
+ userMap[repoOwner.ID] = repoOwner
+ }
+ action.Repo.Owner = repoOwner
}
return nil
}
-// LoadAttributes loads attributes of the actions
-func (actions ActionList) LoadAttributes() error {
- return actions.loadAttributes(db.GetEngine(db.DefaultContext))
+// loadAttributes loads all attributes
+func (actions ActionList) loadAttributes(e db.Engine) error {
+ userMap, err := actions.loadUsers(e)
+ if err != nil {
+ return err
+ }
+
+ if err := actions.loadRepositories(e); err != nil {
+ return err
+ }
+
+ return actions.loadRepoOwner(e, userMap)
}