From fd7d83ace60258acf7139c4c787aa8af75b7ba8c Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 20 May 2022 22:08:52 +0800 Subject: Move almost all functions' parameter db.Engine to context.Context (#19748) * Move almost all functions' parameter db.Engine to context.Context * remove some unnecessary wrap functions --- models/repo/user_repo.go | 37 ------------------------------------- 1 file changed, 37 deletions(-) (limited to 'models/repo/user_repo.go') diff --git a/models/repo/user_repo.go b/models/repo/user_repo.go index 18a04f7267..fe96771796 100644 --- a/models/repo/user_repo.go +++ b/models/repo/user_repo.go @@ -5,10 +5,7 @@ package repo import ( - "context" - "code.gitea.io/gitea/models/db" - user_model "code.gitea.io/gitea/models/user" ) // GetStarredRepos returns the repos starred by a particular user @@ -51,37 +48,3 @@ func GetWatchedRepos(userID int64, private bool, listOptions db.ListOptions) ([] total, err := sess.FindAndCount(&repos) return repos, total, err } - -// CountUserRepositories returns number of repositories user owns. -// Argument private only takes effect when it is false, -// set it true to count all repositories. -func CountUserRepositories(userID int64, private bool) int64 { - return countRepositories(userID, private) -} - -func getRepositoryCount(e db.Engine, ownerID int64) (int64, error) { - return e.Count(&Repository{OwnerID: ownerID}) -} - -func getPublicRepositoryCount(e db.Engine, u *user_model.User) (int64, error) { - return e.Where("is_private = ?", false).Count(&Repository{OwnerID: u.ID}) -} - -func getPrivateRepositoryCount(e db.Engine, u *user_model.User) (int64, error) { - return e.Where("is_private = ?", true).Count(&Repository{OwnerID: u.ID}) -} - -// GetRepositoryCount returns the total number of repositories of user. -func GetRepositoryCount(ctx context.Context, ownerID int64) (int64, error) { - return getRepositoryCount(db.GetEngine(ctx), ownerID) -} - -// GetPublicRepositoryCount returns the total number of public repositories of user. -func GetPublicRepositoryCount(u *user_model.User) (int64, error) { - return getPublicRepositoryCount(db.GetEngine(db.DefaultContext), u) -} - -// GetPrivateRepositoryCount returns the total number of private repositories of user. -func GetPrivateRepositoryCount(u *user_model.User) (int64, error) { - return getPrivateRepositoryCount(db.GetEngine(db.DefaultContext), u) -} -- cgit v1.2.3