mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-31 22:41:03 +00:00 
			
		
		
		
	- Massive replacement of changing `code.gitea.io/gitea` to `forgejo.org`. - Resolves forgejo/discussions#258 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7337 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Reviewed-by: Beowulf <beowulf@beocode.eu> Reviewed-by: Panagiotis "Ivory" Vasilopoulos <git@n0toose.net> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
		
			
				
	
	
		
			54 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2024 The Gitea Authors. All rights reserved.
 | |
| // SPDX-License-Identifier: MIT
 | |
| 
 | |
| package git
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"fmt"
 | |
| 
 | |
| 	"forgejo.org/models/db"
 | |
| 	user_model "forgejo.org/models/user"
 | |
| 	"forgejo.org/modules/container"
 | |
| )
 | |
| 
 | |
| // LFSLockList is a list of LFSLock
 | |
| type LFSLockList []*LFSLock
 | |
| 
 | |
| // LoadAttributes loads the attributes for the given locks
 | |
| func (locks LFSLockList) LoadAttributes(ctx context.Context) error {
 | |
| 	if len(locks) == 0 {
 | |
| 		return nil
 | |
| 	}
 | |
| 
 | |
| 	if err := locks.LoadOwner(ctx); err != nil {
 | |
| 		return fmt.Errorf("load owner: %w", err)
 | |
| 	}
 | |
| 
 | |
| 	return nil
 | |
| }
 | |
| 
 | |
| // LoadOwner loads the owner of the locks
 | |
| func (locks LFSLockList) LoadOwner(ctx context.Context) error {
 | |
| 	if len(locks) == 0 {
 | |
| 		return nil
 | |
| 	}
 | |
| 
 | |
| 	usersIDs := container.FilterSlice(locks, func(lock *LFSLock) (int64, bool) {
 | |
| 		return lock.OwnerID, true
 | |
| 	})
 | |
| 	users := make(map[int64]*user_model.User, len(usersIDs))
 | |
| 	if err := db.GetEngine(ctx).
 | |
| 		In("id", usersIDs).
 | |
| 		Find(&users); err != nil {
 | |
| 		return fmt.Errorf("find users: %w", err)
 | |
| 	}
 | |
| 	for _, v := range locks {
 | |
| 		v.Owner = users[v.OwnerID]
 | |
| 		if v.Owner == nil { // not exist
 | |
| 			v.Owner = user_model.NewGhostUser()
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	return nil
 | |
| }
 |