mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-25 11:22:16 +00:00
Use conditions but not repo ids as query condition (#16839)
* Use conditions but not repo ids as query condition * Improve the performance of pulls/issue * Remove duplicated code * fix lint * Fix bug * Fix stats * More fixes * Fix build * Fix lint * Fix test * Fix build * Adjust the logic * Merge * Fix conflicts * improve the performance * Add comments for the query conditions functions * Some improvements
This commit is contained in:
parent
8fa97a25f0
commit
8ce1b539b1
11 changed files with 401 additions and 427 deletions
|
@ -400,26 +400,6 @@ func HasAccess(userID int64, repo *repo_model.Repository) (bool, error) {
|
|||
return hasAccess(db.DefaultContext, userID, repo)
|
||||
}
|
||||
|
||||
// FilterOutRepoIdsWithoutUnitAccess filter out repos where user has no access to repositories
|
||||
func FilterOutRepoIdsWithoutUnitAccess(u *user_model.User, repoIDs []int64, units ...unit.Type) ([]int64, error) {
|
||||
i := 0
|
||||
for _, rID := range repoIDs {
|
||||
repo, err := repo_model.GetRepositoryByID(rID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
perm, err := GetUserRepoPermission(repo, u)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if perm.CanReadAny(units...) {
|
||||
repoIDs[i] = rID
|
||||
i++
|
||||
}
|
||||
}
|
||||
return repoIDs[:i], nil
|
||||
}
|
||||
|
||||
// GetRepoReaders returns all users that have explicit read access or higher to the repository.
|
||||
func GetRepoReaders(repo *repo_model.Repository) (_ []*user_model.User, err error) {
|
||||
return getUsersWithAccessMode(db.DefaultContext, repo, perm_model.AccessModeRead)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue