mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-11-04 00:11:04 +00:00 
			
		
		
		
	- `releasesToFeedItems` is called to convert release structs to feed items, which is then used to render RSS or Atom feeds. - Optimize the loading of attributes for the releases, introduce `ReleaseList` type which uses caching to load repository and publishers. It also no longer loads release attachments and downloads counts as that is not used in feed items. - Optimize the composing of meta by introducing caching, this operation is especially slow when the owner is an organization. - Add unit test (ensures new `LoadAttributes` works correctly). - Add integration test (ensures that feed output is still as expected). Loading https://codeberg.org/forgejo/forgejo/releases.rss reduced from ~15s to ~1s. (It is currently is deployed on codeberg.org) Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7221 Reviewed-by: Otto <otto@codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
		
			
				
	
	
		
			45 lines
		
	
	
	
		
			1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
	
		
			1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
// Copyright 2025 The Forgejo Authors. All rights reserved.
 | 
						|
// SPDX-License-Identifier: GPL-3.0-or-later
 | 
						|
 | 
						|
package repo
 | 
						|
 | 
						|
import (
 | 
						|
	"context"
 | 
						|
 | 
						|
	user_model "code.gitea.io/gitea/models/user"
 | 
						|
)
 | 
						|
 | 
						|
type ReleaseList []*Release
 | 
						|
 | 
						|
// LoadAttributes loads the repository and publisher for the releases.
 | 
						|
func (r ReleaseList) LoadAttributes(ctx context.Context) error {
 | 
						|
	repoCache := make(map[int64]*Repository)
 | 
						|
	userCache := make(map[int64]*user_model.User)
 | 
						|
 | 
						|
	for _, release := range r {
 | 
						|
		var err error
 | 
						|
		repo, ok := repoCache[release.RepoID]
 | 
						|
		if !ok {
 | 
						|
			repo, err = GetRepositoryByID(ctx, release.RepoID)
 | 
						|
			if err != nil {
 | 
						|
				return err
 | 
						|
			}
 | 
						|
			repoCache[release.RepoID] = repo
 | 
						|
		}
 | 
						|
		release.Repo = repo
 | 
						|
 | 
						|
		publisher, ok := userCache[release.PublisherID]
 | 
						|
		if !ok {
 | 
						|
			publisher, err = user_model.GetUserByID(ctx, release.PublisherID)
 | 
						|
			if err != nil {
 | 
						|
				if !user_model.IsErrUserNotExist(err) {
 | 
						|
					return err
 | 
						|
				}
 | 
						|
				publisher = user_model.NewGhostUser()
 | 
						|
			}
 | 
						|
			userCache[release.PublisherID] = publisher
 | 
						|
		}
 | 
						|
		release.Publisher = publisher
 | 
						|
	}
 | 
						|
	return nil
 | 
						|
}
 |