mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
RSS/Atom support for Repos (#19055)
* support for repos * refactor * advertise the feeds via meta tags * allow feed suffix and feed header * optimize performance
This commit is contained in:
@@ -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
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadRepositories loads actions' all repositories
|
||||
func (actions ActionList) LoadRepositories() ([]*repo_model.Repository, error) {
|
||||
return actions.loadRepositories(db.GetEngine(db.DefaultContext))
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user