diff --git a/models/action.go b/models/action.go index efbe243bed3b9..521de3ff5c3b4 100644 --- a/models/action.go +++ b/models/action.go @@ -328,6 +328,11 @@ type GetFeedsOptions struct { Date string // the day we want activity for: YYYY-MM-DD } +type ExtAction struct { + Action `xorm:"extends"` + Repo *repo_model.Repository `xorm:"extends"` +} + // GetFeeds returns actions according to the provided options func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, error) { if opts.RequestedUser == nil && opts.RequestedTeam == nil && opts.RequestedRepo == nil { @@ -345,12 +350,17 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, error) { opts.SetDefaultValues() sess = db.SetSessionPagination(sess, &opts) - actions := make([]*Action, 0, opts.PageSize) - - if err := sess.Desc("`action`.created_unix").Find(&actions); err != nil { + extActions := make([]*ExtAction, 0, opts.PageSize) + if err := sess.Table("action").Desc("`action`.created_unix").Find(&extActions); err != nil { return nil, fmt.Errorf("Find: %v", err) } + actions := make(ActionList, 0, len(extActions)) + for i := 0; i < len(extActions); i++ { + extActions[i].Action.Repo = extActions[i].Repo + actions = append(actions, &extActions[i].Action) + } + if err := ActionList(actions).loadAttributes(e); err != nil { return nil, fmt.Errorf("LoadAttributes: %v", err) } diff --git a/models/action_list.go b/models/action_list.go index 5f7b17b9de1ef..2e609a9e2e7cd 100644 --- a/models/action_list.go +++ b/models/action_list.go @@ -49,6 +49,9 @@ func (actions ActionList) loadUsers(e db.Engine) (map[int64]*user_model.User, er func (actions ActionList) getRepoIDs() []int64 { repoIDs := make(map[int64]struct{}, len(actions)) for _, action := range actions { + if action.Repo != nil { + continue + } if _, ok := repoIDs[action.RepoID]; !ok { repoIDs[action.RepoID] = struct{}{} } @@ -62,6 +65,10 @@ func (actions ActionList) loadRepositories(e db.Engine) error { } repoIDs := actions.getRepoIDs() + if len(repoIDs) == 0 { + return nil + } + repoMaps := make(map[int64]*repo_model.Repository, len(repoIDs)) err := e.In("id", repoIDs).Find(&repoMaps) if err != nil {