summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-12-03 03:48:26 +0100
committerGitHub <noreply@github.com>2022-12-03 03:48:26 +0100
commit0a7d3ff786508284224ada17956a65bb759d9265 (patch)
tree4860fca95c1432ab59c6723ee2b053b1c7d6779d /models
parentRemove deprecated packages & staticcheck fixes (#22012) (diff)
downloadforgejo-0a7d3ff786508284224ada17956a65bb759d9265.tar.xz
forgejo-0a7d3ff786508284224ada17956a65bb759d9265.zip
refactor some functions to support ctx as first parameter (#21878)
Co-authored-by: KN4CK3R <admin@oldschoolhack.me> Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'models')
-rw-r--r--models/activities/action.go22
-rw-r--r--models/activities/action_list.go2
-rw-r--r--models/activities/notification.go6
-rw-r--r--models/asymkey/gpg_key_commit_verification.go2
-rw-r--r--models/git/branches.go19
-rw-r--r--models/git/branches_test.go4
-rw-r--r--models/git/commit_status.go4
-rw-r--r--models/git/lfs_lock.go2
-rw-r--r--models/issues/assignees.go2
-rw-r--r--models/issues/assignees_test.go6
-rw-r--r--models/issues/comment.go6
-rw-r--r--models/issues/dependency_test.go2
-rw-r--r--models/issues/issue.go4
-rw-r--r--models/issues/issue_xref.go2
-rw-r--r--models/issues/milestone.go2
-rw-r--r--models/issues/pull.go17
-rw-r--r--models/issues/reaction.go2
-rw-r--r--models/issues/review.go8
-rw-r--r--models/issues/stopwatch_test.go6
-rw-r--r--models/issues/tracked_time.go4
-rw-r--r--models/issues/tracked_time_test.go2
-rw-r--r--models/org.go2
-rw-r--r--models/org_team.go26
-rw-r--r--models/organization/org.go2
-rw-r--r--models/organization/org_user_test.go4
-rw-r--r--models/organization/team.go10
-rw-r--r--models/organization/team_test.go4
-rw-r--r--models/packages/descriptor.go6
-rw-r--r--models/perm/access/access.go2
-rw-r--r--models/perm/access/repo_permission.go2
-rw-r--r--models/project/project.go2
-rw-r--r--models/pull/automerge.go2
-rw-r--r--models/repo.go8
-rw-r--r--models/repo/collaboration.go2
-rw-r--r--models/repo/fork_test.go4
-rw-r--r--models/repo/issue.go2
-rw-r--r--models/repo/mirror.go2
-rw-r--r--models/repo/pushmirror.go2
-rw-r--r--models/repo/release.go4
-rw-r--r--models/repo/repo.go32
-rw-r--r--models/repo/repo_test.go2
-rw-r--r--models/repo_collaboration.go2
-rw-r--r--models/repo_transfer.go6
-rw-r--r--models/user/email_address.go2
-rw-r--r--models/user/email_address_test.go2
-rw-r--r--models/user/user.go11
-rw-r--r--models/user/user_test.go2
47 files changed, 123 insertions, 146 deletions
diff --git a/models/activities/action.go b/models/activities/action.go
index 80c117dc95..1ac1be7135 100644
--- a/models/activities/action.go
+++ b/models/activities/action.go
@@ -114,12 +114,12 @@ func (a *Action) GetOpType() ActionType {
}
// LoadActUser loads a.ActUser
-func (a *Action) LoadActUser() {
+func (a *Action) LoadActUser(ctx context.Context) {
if a.ActUser != nil {
return
}
var err error
- a.ActUser, err = user_model.GetUserByID(a.ActUserID)
+ a.ActUser, err = user_model.GetUserByID(ctx, a.ActUserID)
if err == nil {
return
} else if user_model.IsErrUserNotExist(err) {
@@ -129,12 +129,12 @@ func (a *Action) LoadActUser() {
}
}
-func (a *Action) loadRepo() {
+func (a *Action) loadRepo(ctx context.Context) {
if a.Repo != nil {
return
}
var err error
- a.Repo, err = repo_model.GetRepositoryByID(a.RepoID)
+ a.Repo, err = repo_model.GetRepositoryByID(ctx, a.RepoID)
if err != nil {
log.Error("repo_model.GetRepositoryByID(%d): %v", a.RepoID, err)
}
@@ -142,13 +142,13 @@ func (a *Action) loadRepo() {
// GetActFullName gets the action's user full name.
func (a *Action) GetActFullName() string {
- a.LoadActUser()
+ a.LoadActUser(db.DefaultContext)
return a.ActUser.FullName
}
// GetActUserName gets the action's user name.
func (a *Action) GetActUserName() string {
- a.LoadActUser()
+ a.LoadActUser(db.DefaultContext)
return a.ActUser.Name
}
@@ -179,7 +179,7 @@ func (a *Action) GetDisplayNameTitle() string {
// GetRepoUserName returns the name of the action repository owner.
func (a *Action) GetRepoUserName() string {
- a.loadRepo()
+ a.loadRepo(db.DefaultContext)
return a.Repo.OwnerName
}
@@ -191,7 +191,7 @@ func (a *Action) ShortRepoUserName() string {
// GetRepoName returns the name of the action repository.
func (a *Action) GetRepoName() string {
- a.loadRepo()
+ a.loadRepo(db.DefaultContext)
return a.Repo.Name
}
@@ -379,7 +379,7 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
cond := builder.NewCond()
if opts.RequestedTeam != nil && opts.RequestedUser == nil {
- org, err := user_model.GetUserByID(opts.RequestedTeam.OrgID)
+ org, err := user_model.GetUserByID(db.DefaultContext, opts.RequestedTeam.OrgID)
if err != nil {
return nil, err
}
@@ -489,7 +489,7 @@ func NotifyWatchers(ctx context.Context, actions ...*Action) error {
}
if repoChanged {
- act.loadRepo()
+ act.loadRepo(ctx)
repo = act.Repo
// check repo owner exist.
@@ -514,7 +514,7 @@ func NotifyWatchers(ctx context.Context, actions ...*Action) error {
permIssue = make([]bool, len(watchers))
permPR = make([]bool, len(watchers))
for i, watcher := range watchers {
- user, err := user_model.GetUserByIDCtx(ctx, watcher.UserID)
+ user, err := user_model.GetUserByID(ctx, watcher.UserID)
if err != nil {
permCode[i] = false
permIssue[i] = false
diff --git a/models/activities/action_list.go b/models/activities/action_list.go
index 0979434f76..3d74397c69 100644
--- a/models/activities/action_list.go
+++ b/models/activities/action_list.go
@@ -81,7 +81,7 @@ func (actions ActionList) loadRepoOwner(ctx context.Context, userMap map[int64]*
}
repoOwner, ok := userMap[action.Repo.OwnerID]
if !ok {
- repoOwner, err = user_model.GetUserByIDCtx(ctx, action.Repo.OwnerID)
+ repoOwner, err = user_model.GetUserByID(ctx, action.Repo.OwnerID)
if err != nil {
if user_model.IsErrUserNotExist(err) {
continue
diff --git a/models/activities/notification.go b/models/activities/notification.go
index 9aa4b87628..d20a53a41d 100644
--- a/models/activities/notification.go
+++ b/models/activities/notification.go
@@ -245,7 +245,7 @@ func createOrUpdateIssueNotifications(ctx context.Context, issueID, commentID, n
// notify
for userID := range toNotify {
issue.Repo.Units = nil
- user, err := user_model.GetUserByIDCtx(ctx, userID)
+ user, err := user_model.GetUserByID(ctx, userID)
if err != nil {
if user_model.IsErrUserNotExist(err) {
continue
@@ -388,7 +388,7 @@ func (n *Notification) LoadAttributes(ctx context.Context) (err error) {
func (n *Notification) loadRepo(ctx context.Context) (err error) {
if n.Repository == nil {
- n.Repository, err = repo_model.GetRepositoryByIDCtx(ctx, n.RepoID)
+ n.Repository, err = repo_model.GetRepositoryByID(ctx, n.RepoID)
if err != nil {
return fmt.Errorf("getRepositoryByID [%d]: %w", n.RepoID, err)
}
@@ -425,7 +425,7 @@ func (n *Notification) loadComment(ctx context.Context) (err error) {
func (n *Notification) loadUser(ctx context.Context) (err error) {
if n.User == nil {
- n.User, err = user_model.GetUserByIDCtx(ctx, n.UserID)
+ n.User, err = user_model.GetUserByID(ctx, n.UserID)
if err != nil {
return fmt.Errorf("getUserByID [%d]: %w", n.UserID, err)
}
diff --git a/models/asymkey/gpg_key_commit_verification.go b/models/asymkey/gpg_key_commit_verification.go
index 1cdd748e35..1b88fb8b13 100644
--- a/models/asymkey/gpg_key_commit_verification.go
+++ b/models/asymkey/gpg_key_commit_verification.go
@@ -426,7 +426,7 @@ func hashAndVerifyForKeyID(sig *packet.Signature, payload string, committer *use
Email: email,
}
if key.OwnerID != 0 {
- owner, err := user_model.GetUserByID(key.OwnerID)
+ owner, err := user_model.GetUserByID(db.DefaultContext, key.OwnerID)
if err == nil {
signer = owner
} else if !user_model.IsErrUserNotExist(err) {
diff --git a/models/git/branches.go b/models/git/branches.go
index 87246ed149..c02ab0a888 100644
--- a/models/git/branches.go
+++ b/models/git/branches.go
@@ -73,10 +73,10 @@ func (protectBranch *ProtectedBranch) CanUserPush(userID int64) bool {
}
if !protectBranch.EnableWhitelist {
- if user, err := user_model.GetUserByID(userID); err != nil {
+ if user, err := user_model.GetUserByID(db.DefaultContext, userID); err != nil {
log.Error("GetUserByID: %v", err)
return false
- } else if repo, err := repo_model.GetRepositoryByID(protectBranch.RepoID); err != nil {
+ } else if repo, err := repo_model.GetRepositoryByID(db.DefaultContext, protectBranch.RepoID); err != nil {
log.Error("repo_model.GetRepositoryByID: %v", err)
return false
} else if writeAccess, err := access_model.HasAccessUnit(db.DefaultContext, user, repo, unit.TypeCode, perm.AccessModeWrite); err != nil {
@@ -127,13 +127,8 @@ func IsUserMergeWhitelisted(ctx context.Context, protectBranch *ProtectedBranch,
}
// IsUserOfficialReviewer check if user is official reviewer for the branch (counts towards required approvals)
-func IsUserOfficialReviewer(protectBranch *ProtectedBranch, user *user_model.User) (bool, error) {
- return IsUserOfficialReviewerCtx(db.DefaultContext, protectBranch, user)
-}
-
-// IsUserOfficialReviewerCtx check if user is official reviewer for the branch (counts towards required approvals)
-func IsUserOfficialReviewerCtx(ctx context.Context, protectBranch *ProtectedBranch, user *user_model.User) (bool, error) {
- repo, err := repo_model.GetRepositoryByIDCtx(ctx, protectBranch.RepoID)
+func IsUserOfficialReviewer(ctx context.Context, protectBranch *ProtectedBranch, user *user_model.User) (bool, error) {
+ repo, err := repo_model.GetRepositoryByID(ctx, protectBranch.RepoID)
if err != nil {
return false, err
}
@@ -375,7 +370,7 @@ func updateUserWhitelist(ctx context.Context, repo *repo_model.Repository, curre
whitelist = make([]int64, 0, len(newWhitelist))
for _, userID := range newWhitelist {
- user, err := user_model.GetUserByIDCtx(ctx, userID)
+ user, err := user_model.GetUserByID(ctx, userID)
if err != nil {
return nil, fmt.Errorf("GetUserByID [user_id: %d, repo_id: %d]: %w", userID, repo.ID, err)
}
@@ -494,8 +489,8 @@ func RemoveDeletedBranchByID(repoID, id int64) (err error) {
// LoadUser loads the user that deleted the branch
// When there's no user found it returns a user_model.NewGhostUser
-func (deletedBranch *DeletedBranch) LoadUser() {
- user, err := user_model.GetUserByID(deletedBranch.DeletedByID)
+func (deletedBranch *DeletedBranch) LoadUser(ctx context.Context) {
+ user, err := user_model.GetUserByID(ctx, deletedBranch.DeletedByID)
if err != nil {
user = user_model.NewGhostUser()
}
diff --git a/models/git/branches_test.go b/models/git/branches_test.go
index 038a4f6686..56f416622e 100644
--- a/models/git/branches_test.go
+++ b/models/git/branches_test.go
@@ -48,13 +48,13 @@ func TestDeletedBranchLoadUser(t *testing.T) {
branch := getDeletedBranch(t, firstBranch)
assert.Nil(t, branch.DeletedBy)
- branch.LoadUser()
+ branch.LoadUser(db.DefaultContext)
assert.NotNil(t, branch.DeletedBy)
assert.Equal(t, "user1", branch.DeletedBy.Name)
branch = getDeletedBranch(t, secondBranch)
assert.Nil(t, branch.DeletedBy)
- branch.LoadUser()
+ branch.LoadUser(db.DefaultContext)
assert.NotNil(t, branch.DeletedBy)
assert.Equal(t, "Ghost", branch.DeletedBy.Name)
}
diff --git a/models/git/commit_status.go b/models/git/commit_status.go
index 928f1771fe..0fb0bc66af 100644
--- a/models/git/commit_status.go
+++ b/models/git/commit_status.go
@@ -114,13 +114,13 @@ func GetNextCommitStatusIndex(ctx context.Context, repoID int64, sha string) (in
func (status *CommitStatus) loadAttributes(ctx context.Context) (err error) {
if status.Repo == nil {
- status.Repo, err = repo_model.GetRepositoryByIDCtx(ctx, status.RepoID)
+ status.Repo, err = repo_model.GetRepositoryByID(ctx, status.RepoID)
if err != nil {
return fmt.Errorf("getRepositoryByID [%d]: %w", status.RepoID, err)
}
}
if status.Creator == nil && status.CreatorID > 0 {
- status.Creator, err = user_model.GetUserByIDCtx(ctx, status.CreatorID)
+ status.Creator, err = user_model.GetUserByID(ctx, status.CreatorID)
if err != nil {
return fmt.Errorf("getUserByID [%d]: %w", status.CreatorID, err)
}
diff --git a/models/git/lfs_lock.go b/models/git/lfs_lock.go
index 3d765ea22b..dc5b0a2ced 100644
--- a/models/git/lfs_lock.go
+++ b/models/git/lfs_lock.go
@@ -167,7 +167,7 @@ func CheckLFSAccessForRepo(ctx context.Context, ownerID int64, repo *repo_model.
if ownerID == 0 {
return ErrLFSUnauthorizedAction{repo.ID, "undefined", mode}
}
- u, err := user_model.GetUserByIDCtx(ctx, ownerID)
+ u, err := user_model.GetUserByID(ctx, ownerID)
if err != nil {
return err
}
diff --git a/models/issues/assignees.go b/models/issues/assignees.go
index 25ecd4b05c..d3a1f5ffe8 100644
--- a/models/issues/assignees.go
+++ b/models/issues/assignees.go
@@ -118,7 +118,7 @@ func toggleIssueAssignee(ctx context.Context, issue *Issue, doer *user_model.Use
// toggles user assignee state in database
func toggleUserAssignee(ctx context.Context, issue *Issue, assigneeID int64) (removed bool, err error) {
// Check if the user exists
- assignee, err := user_model.GetUserByIDCtx(ctx, assigneeID)
+ assignee, err := user_model.GetUserByID(ctx, assigneeID)
if err != nil {
return false, err
}
diff --git a/models/issues/assignees_test.go b/models/issues/assignees_test.go
index 7f18569d49..8a2cef8acd 100644
--- a/models/issues/assignees_test.go
+++ b/models/issues/assignees_test.go
@@ -22,17 +22,17 @@ func TestUpdateAssignee(t *testing.T) {
assert.NoError(t, err)
// Assign multiple users
- user2, err := user_model.GetUserByID(2)
+ user2, err := user_model.GetUserByID(db.DefaultContext, 2)
assert.NoError(t, err)
_, _, err = issues_model.ToggleIssueAssignee(issue, &user_model.User{ID: 1}, user2.ID)
assert.NoError(t, err)
- user3, err := user_model.GetUserByID(3)
+ user3, err := user_model.GetUserByID(db.DefaultContext, 3)
assert.NoError(t, err)
_, _, err = issues_model.ToggleIssueAssignee(issue, &user_model.User{ID: 1}, user3.ID)
assert.NoError(t, err)
- user1, err := user_model.GetUserByID(1) // This user is already assigned (see the definition in fixtures), so running UpdateAssignee should unassign him
+ user1, err := user_model.GetUserByID(db.DefaultContext, 1) // This user is already assigned (see the definition in fixtures), so running UpdateAssignee should unassign him
assert.NoError(t, err)
_, _, err = issues_model.ToggleIssueAssignee(issue, &user_model.User{ID: 1}, user1.ID)
assert.NoError(t, err)
diff --git a/models/issues/comment.go b/models/issues/comment.go
index 0aaa870b46..f49c6e2c1f 100644
--- a/models/issues/comment.go
+++ b/models/issues/comment.go
@@ -350,7 +350,7 @@ func (c *Comment) LoadPoster(ctx context.Context) (err error) {
return nil
}
- c.Poster, err = user_model.GetUserByIDCtx(ctx, c.PosterID)
+ c.Poster, err = user_model.GetUserByID(ctx, c.PosterID)
if err != nil {
if user_model.IsErrUserNotExist(err) {
c.PosterID = -1
@@ -580,7 +580,7 @@ func (c *Comment) LoadAssigneeUserAndTeam() error {
var err error
if c.AssigneeID > 0 && c.Assignee == nil {
- c.Assignee, err = user_model.GetUserByIDCtx(db.DefaultContext, c.AssigneeID)
+ c.Assignee, err = user_model.GetUserByID(db.DefaultContext, c.AssigneeID)
if err != nil {
if !user_model.IsErrUserNotExist(err) {
return err
@@ -615,7 +615,7 @@ func (c *Comment) LoadResolveDoer() (err error) {
if c.ResolveDoerID == 0 || c.Type != CommentTypeCode {
return nil
}
- c.ResolveDoer, err = user_model.GetUserByIDCtx(db.DefaultContext, c.ResolveDoerID)
+ c.ResolveDoer, err = user_model.GetUserByID(db.DefaultContext, c.ResolveDoerID)
if err != nil {
if user_model.IsErrUserNotExist(err) {
c.ResolveDoer = user_model.NewGhostUser()
diff --git a/models/issues/dependency_test.go b/models/issues/dependency_test.go
index 7af30b2019..cdc8e3182d 100644
--- a/models/issues/dependency_test.go
+++ b/models/issues/dependency_test.go
@@ -18,7 +18,7 @@ func TestCreateIssueDependency(t *testing.T) {
// Prepare
assert.NoError(t, unittest.PrepareTestDatabase())
- user1, err := user_model.GetUserByID(1)
+ user1, err := user_model.GetUserByID(db.DefaultContext, 1)
assert.NoError(t, err)
issue1, err := issues_model.GetIssueByID(db.DefaultContext, 1)
diff --git a/models/issues/issue.go b/models/issues/issue.go
index 488a17609e..1d66996ee0 100644
--- a/models/issues/issue.go
+++ b/models/issues/issue.go
@@ -193,7 +193,7 @@ func (issue *Issue) IsOverdue() bool {
// LoadRepo loads issue's repository
func (issue *Issue) LoadRepo(ctx context.Context) (err error) {
if issue.Repo == nil {
- issue.Repo, err = repo_model.GetRepositoryByIDCtx(ctx, issue.RepoID)
+ issue.Repo, err = repo_model.GetRepositoryByID(ctx, issue.RepoID)
if err != nil {
return fmt.Errorf("getRepositoryByID [%d]: %w", issue.RepoID, err)
}
@@ -242,7 +242,7 @@ func (issue *Issue) LoadLabels(ctx context.Context) (err error) {
// LoadPoster loads poster
func (issue *Issue) LoadPoster(ctx context.Context) (err error) {
if issue.Poster == nil {
- issue.Poster, err = user_model.GetUserByIDCtx(ctx, issue.PosterID)
+ issue.Poster, err = user_model.GetUserByID(ctx, issue.PosterID)
if err != nil {
issue.PosterID = -1
issue.Poster = user_model.NewGhostUser()
diff --git a/models/issues/issue_xref.go b/models/issues/issue_xref.go
index a965cf7340..267ccc73a0 100644
--- a/models/issues/issue_xref.go
+++ b/models/issues/issue_xref.go
@@ -148,7 +148,7 @@ func (issue *Issue) getCrossReferences(stdCtx context.Context, ctx *crossReferen
refRepo = ctx.OrigIssue.Repo
} else {
// Issues in other repositories
- refRepo, err = repo_model.GetRepositoryByOwnerAndNameCtx(stdCtx, ref.Owner, ref.Name)
+ refRepo, err = repo_model.GetRepositoryByOwnerAndName(stdCtx, ref.Owner, ref.Name)
if err != nil {
if repo_model.IsErrRepoNotExist(err) {
continue
diff --git a/models/issues/milestone.go b/models/issues/milestone.go
index 7c2ce407e6..8255db38f9 100644
--- a/models/issues/milestone.go
+++ b/models/issues/milestone.go
@@ -284,7 +284,7 @@ func DeleteMilestoneByRepoID(repoID, id int64) error {
return err
}
- repo, err := repo_model.GetRepositoryByID(m.RepoID)
+ repo, err := repo_model.GetRepositoryByID(db.DefaultContext, m.RepoID)
if err != nil {
return err
}
diff --git a/models/issues/pull.go b/models/issues/pull.go
index 9105dd4d3a..7af9400d17 100644
--- a/models/issues/pull.go
+++ b/models/issues/pull.go
@@ -223,7 +223,7 @@ func (pr *PullRequest) MustHeadUserName(ctx context.Context) string {
// Note: don't try to get Issue because will end up recursive querying.
func (pr *PullRequest) LoadAttributes(ctx context.Context) (err error) {
if pr.HasMerged && pr.Merger == nil {
- pr.Merger, err = user_model.GetUserByIDCtx(ctx, pr.MergerID)
+ pr.Merger, err = user_model.GetUserByID(ctx, pr.MergerID)
if user_model.IsErrUserNotExist(err) {
pr.MergerID = -1
pr.Merger = user_model.NewGhostUser()
@@ -248,9 +248,9 @@ func (pr *PullRequest) LoadHeadRepo(ctx context.Context) (err error) {
}
}
- pr.HeadRepo, err = repo_model.GetRepositoryByIDCtx(ctx, pr.HeadRepoID)
+ pr.HeadRepo, err = repo_model.GetRepositoryByID(ctx, pr.HeadRepoID)
if err != nil && !repo_model.IsErrRepoNotExist(err) { // Head repo maybe deleted, but it should still work
- return fmt.Errorf("getRepositoryByID(head): %w", err)
+ return fmt.Errorf("GetRepositoryByID(head): %w", err)
}
pr.isHeadRepoLoaded = true
}
@@ -273,7 +273,7 @@ func (pr *PullRequest) LoadBaseRepo(ctx context.Context) (err error) {
return nil
}
- pr.BaseRepo, err = repo_model.GetRepositoryByIDCtx(ctx, pr.BaseRepoID)
+ pr.BaseRepo, err = repo_model.GetRepositoryByID(ctx, pr.BaseRepoID)
if err != nil {
return fmt.Errorf("repo_model.GetRepositoryByID(base): %w", err)
}
@@ -294,18 +294,13 @@ func (pr *PullRequest) LoadIssue(ctx context.Context) (err error) {
}
// LoadProtectedBranch loads the protected branch of the base branch
-func (pr *PullRequest) LoadProtectedBranch() (err error) {
- return pr.LoadProtectedBranchCtx(db.DefaultContext)
-}
-
-// LoadProtectedBranchCtx loads the protected branch of the base branch
-func (pr *PullRequest) LoadProtectedBranchCtx(ctx context.Context) (err error) {
+func (pr *PullRequest) LoadProtectedBranch(ctx context.Context) (err error) {
if pr.ProtectedBranch == nil {
if pr.BaseRepo == nil {
if pr.BaseRepoID == 0 {
return nil
}
- pr.BaseRepo, err = repo_model.GetRepositoryByIDCtx(ctx, pr.BaseRepoID)
+ pr.BaseRepo, err = repo_model.GetRepositoryByID(ctx, pr.BaseRepoID)
if err != nil {
return
}
diff --git a/models/issues/reaction.go b/models/issues/reaction.go
index 381881ff61..293dfa3fd1 100644
--- a/models/issues/reaction.go
+++ b/models/issues/reaction.go
@@ -75,7 +75,7 @@ func (r *Reaction) LoadUser() (*user_model.User, error) {
if r.User != nil {
return r.User, nil
}
- user, err := user_model.GetUserByIDCtx(db.DefaultContext, r.UserID)
+ user, err := user_model.GetUserByID(db.DefaultContext, r.UserID)
if err != nil {
return nil, err
}
diff --git a/models/issues/review.go b/models/issues/review.go
index 0b50763fdc..db2d2686cb 100644
--- a/models/issues/review.go
+++ b/models/issues/review.go
@@ -158,7 +158,7 @@ func (r *Review) LoadReviewer(ctx context.Context) (err error) {
if r.ReviewerID == 0 || r.Reviewer != nil {
return
}
- r.Reviewer, err = user_model.GetUserByIDCtx(ctx, r.ReviewerID)
+ r.Reviewer, err = user_model.GetUserByID(ctx, r.ReviewerID)
return err
}
@@ -263,7 +263,7 @@ func IsOfficialReviewer(ctx context.Context, issue *Issue, reviewers ...*user_mo
if err != nil {
return false, err
}
- if err = pr.LoadProtectedBranchCtx(ctx); err != nil {
+ if err = pr.LoadProtectedBranch(ctx); err != nil {
return false, err
}
if pr.ProtectedBranch == nil {
@@ -271,7 +271,7 @@ func IsOfficialReviewer(ctx context.Context, issue *Issue, reviewers ...*user_mo
}
for _, reviewer := range reviewers {
- official, err := git_model.IsUserOfficialReviewerCtx(ctx, pr.ProtectedBranch, reviewer)
+ official, err := git_model.IsUserOfficialReviewer(ctx, pr.ProtectedBranch, reviewer)
if official || err != nil {
return official, err
}
@@ -286,7 +286,7 @@ func IsOfficialReviewerTeam(ctx context.Context, issue *Issue, team *organizatio
if err != nil {
return false, err
}
- if err = pr.LoadProtectedBranchCtx(ctx); err != nil {
+ if err = pr.LoadProtectedBranch(ctx); err != nil {
return false, err
}
if pr.ProtectedBranch == nil {
diff --git a/models/issues/stopwatch_test.go b/models/issues/stopwatch_test.go
index 7745bc513c..ec2778aa81 100644
--- a/models/issues/stopwatch_test.go
+++ b/models/issues/stopwatch_test.go
@@ -18,7 +18,7 @@ import (
func TestCancelStopwatch(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- user1, err := user_model.GetUserByID(1)
+ user1, err := user_model.GetUserByID(db.DefaultContext, 1)
assert.NoError(t, err)
issue1, err := issues_model.GetIssueByID(db.DefaultContext, 1)
@@ -58,9 +58,9 @@ func TestHasUserStopwatch(t *testing.T) {
func TestCreateOrStopIssueStopwatch(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- user2, err := user_model.GetUserByID(2)
+ user2, err := user_model.GetUserByID(db.DefaultContext, 2)
assert.NoError(t, err)
- user3, err := user_model.GetUserByID(3)
+ user3, err := user_model.GetUserByID(db.DefaultContext, 3)
assert.NoError(t, err)
issue1, err := issues_model.GetIssueByID(db.DefaultContext, 1)
diff --git a/models/issues/tracked_time.go b/models/issues/tracked_time.go
index 6d25975459..2de63a3a45 100644
--- a/models/issues/tracked_time.go
+++ b/models/issues/tracked_time.go
@@ -57,7 +57,7 @@ func (t *TrackedTime) loadAttributes(ctx context.Context) (err error) {
}
}
if t.User == nil {
- t.User, err = user_model.GetUserByIDCtx(ctx, t.UserID)
+ t.User, err = user_model.GetUserByID(ctx, t.UserID)
if err != nil {
return
}
@@ -205,7 +205,7 @@ func TotalTimes(options *FindTrackedTimesOptions) (map[*user_model.User]string,
totalTimes := make(map[*user_model.User]string)
// Fetching User and making time human readable
for userID, total := range totalTimesByUser {
- user, err := user_model.GetUserByID(userID)
+ user, err := user_model.GetUserByID(db.DefaultContext, userID)
if err != nil {
if user_model.IsErrUserNotExist(err) {
continue
diff --git a/models/issues/tracked_time_test.go b/models/issues/tracked_time_test.go
index b3174c7c82..becfd79d41 100644
--- a/models/issues/tracked_time_test.go
+++ b/models/issues/tracked_time_test.go
@@ -18,7 +18,7 @@ import (
func TestAddTime(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- user3, err := user_model.GetUserByID(3)
+ user3, err := user_model.GetUserByID(db.DefaultContext, 3)
assert.NoError(t, err)
issue1, err := issues_model.GetIssueByID(db.DefaultContext, 1)
diff --git a/models/org.go b/models/org.go
index 1c9383fe8d..5f0e678ab4 100644
--- a/models/org.go
+++ b/models/org.go
@@ -43,7 +43,7 @@ func removeOrgUser(ctx context.Context, orgID, userID int64) error {
return err
}
if t.NumMembers == 1 {
- if err := t.GetMembersCtx(ctx); err != nil {
+ if err := t.LoadMembers(ctx); err != nil {
return err
}
if t.Members[0].ID == userID {
diff --git a/models/org_team.go b/models/org_team.go
index 62376192ab..a5a2575eec 100644
--- a/models/org_team.go
+++ b/models/org_team.go
@@ -41,7 +41,7 @@ func AddRepository(ctx context.Context, t *organization.Team, repo *repo_model.R
// Make all team members watch this repo if enabled in global settings
if setting.Service.AutoWatchNewRepos {
- if err = t.GetMembersCtx(ctx); err != nil {
+ if err = t.LoadMembers(ctx); err != nil {
return fmt.Errorf("getMembers: %w", err)
}
for _, u := range t.Members {
@@ -213,7 +213,7 @@ func RemoveRepository(t *organization.Team, repoID int64) error {
return nil
}
- repo, err := repo_model.GetRepositoryByID(repoID)
+ repo, err := repo_model.GetRepositoryByID(db.DefaultContext, repoID)
if err != nil {
return err
}
@@ -349,8 +349,8 @@ func UpdateTeam(t *organization.Team, authChanged, includeAllChanged bool) (err
// Update access for team members if needed.
if authChanged {
- if err = t.GetRepositoriesCtx(ctx); err != nil {
- return fmt.Errorf("getRepositories: %w", err)
+ if err = t.LoadRepositories(ctx); err != nil {
+ return fmt.Errorf("LoadRepositories: %w", err)
}
for _, repo := range t.Repos {
@@ -381,11 +381,11 @@ func DeleteTeam(t *organization.Team) error {
defer committer.Close()
sess := db.GetEngine(ctx)
- if err := t.GetRepositoriesCtx(ctx); err != nil {
+ if err := t.LoadRepositories(ctx); err != nil {
return err
}
- if err := t.GetMembersCtx(ctx); err != nil {
+ if err := t.LoadMembers(ctx); err != nil {
return err
}
@@ -516,10 +516,16 @@ func AddTeamMember(team *organization.Team, userID int64) error {
}
}
- // watch could be failed, so run it in a goroutine
+ if err := committer.Commit(); err != nil {
+ return err
+ }
+ committer.Close()
+
+ // this behaviour may spend much time so run it in a goroutine
+ // FIXME: Update watch repos batchly
if setting.Service.AutoWatchNewRepos {
// Get team and its repositories.
- if err := team.GetRepositoriesCtx(db.DefaultContext); err != nil {
+ if err := team.LoadRepositories(db.DefaultContext); err != nil {
log.Error("getRepositories failed: %v", err)
}
go func(repos []*repo_model.Repository) {
@@ -531,7 +537,7 @@ func AddTeamMember(team *organization.Team, userID int64) error {
}(team.Repos)
}
- return committer.Commit()
+ return nil
}
func removeTeamMember(ctx context.Context, team *organization.Team, userID int64) error {
@@ -548,7 +554,7 @@ func removeTeamMember(ctx context.Context, team *organization.Team, userID int64
team.NumMembers--
- if err := team.GetRepositoriesCtx(ctx); err != nil {
+ if err := team.LoadRepositories(ctx); err != nil {
return err
}
diff --git a/models/organization/org.go b/models/organization/org.go
index ef7b834ad3..a5b07d5aae 100644
--- a/models/organization/org.go
+++ b/models/organization/org.go
@@ -701,7 +701,7 @@ func AccessibleReposEnv(ctx context.Context, org *Organization, userID int64) (A
var user *user_model.User
if userID > 0 {
- u, err := user_model.GetUserByIDCtx(ctx, userID)
+ u, err := user_model.GetUserByID(ctx, userID)
if err != nil {
return nil, err
}
diff --git a/models/organization/org_user_test.go b/models/organization/org_user_test.go
index 1da17631e3..edd0aa3ea0 100644
--- a/models/organization/org_user_test.go
+++ b/models/organization/org_user_test.go
@@ -37,7 +37,7 @@ func TestUserIsPublicMember(t *testing.T) {
}
func testUserIsPublicMember(t *testing.T, uid, orgID int64, expected bool) {
- user, err := user_model.GetUserByID(uid)
+ user, err := user_model.GetUserByID(db.DefaultContext, uid)
assert.NoError(t, err)
is, err := organization.IsPublicMembership(orgID, user.ID)
assert.NoError(t, err)
@@ -65,7 +65,7 @@ func TestIsUserOrgOwner(t *testing.T) {
}
func testIsUserOrgOwner(t *testing.T, uid, orgID int64, expected bool) {
- user, err := user_model.GetUserByID(uid)
+ user, err := user_model.GetUserByID(db.DefaultContext, uid)
assert.NoError(t, err)
is, err := organization.IsOrganizationOwner(db.DefaultContext, orgID, user.ID)
assert.NoError(t, err)
diff --git a/models/organization/team.go b/models/organization/team.go
index f6d71845df..86ea30c801 100644
--- a/models/organization/team.go
+++ b/models/organization/team.go
@@ -222,8 +222,8 @@ func (t *Team) IsMember(userID int64) bool {
return isMember
}
-// GetRepositoriesCtx returns paginated repositories in team of organization.
-func (t *Team) GetRepositoriesCtx(ctx context.Context) (err error) {
+// LoadRepositories returns paginated repositories in team of organization.
+func (t *Team) LoadRepositories(ctx context.Context) (err error) {
if t.Repos != nil {
return nil
}
@@ -233,8 +233,8 @@ func (t *Team) GetRepositoriesCtx(ctx context.Context) (err error) {
return err
}
-// GetMembersCtx returns paginated members in team of organization.
-func (t *Team) GetMembersCtx(ctx context.Context) (err error) {
+// LoadMembers returns paginated members in team of organization.
+func (t *Team) LoadMembers(ctx context.Context) (err error) {
t.Members, err = GetTeamMembers(ctx, &SearchMembersOptions{
TeamID: t.ID,
})
@@ -248,7 +248,7 @@ func (t *Team) UnitEnabled(tp unit.Type) bool {
// UnitAccessMode returns if the team has the given unit type enabled
// it is called in templates, should not be replaced by `UnitAccessModeCtx(ctx ...)`
-func (t *Team) UnitAccessMode(tp unit.Type) perm.AccessMode {
+func (t *Team) UnitAccessMode(tp unit.Type) perm.AccessMode { // Notice: It will be used in template, don't remove it directly
return t.UnitAccessModeCtx(db.DefaultContext, tp)
}
diff --git a/models/organization/team_test.go b/models/organization/team_test.go
index d324c6d0da..c63b83aab7 100644
--- a/models/organization/team_test.go
+++ b/models/organization/team_test.go
@@ -42,7 +42,7 @@ func TestTeam_GetRepositories(t *testing.T) {
test := func(teamID int64) {
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
- assert.NoError(t, team.GetRepositoriesCtx(db.DefaultContext))
+ assert.NoError(t, team.LoadRepositories(db.DefaultContext))
assert.Len(t, team.Repos, team.NumRepos)
for _, repo := range team.Repos {
unittest.AssertExistsAndLoadBean(t, &organization.TeamRepo{TeamID: teamID, RepoID: repo.ID})
@@ -57,7 +57,7 @@ func TestTeam_GetMembers(t *testing.T) {
test := func(teamID int64) {
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
- assert.NoError(t, team.GetMembersCtx(db.DefaultContext))
+ assert.NoError(t, team.LoadMembers(db.DefaultContext))
assert.Len(t, team.Members, team.NumMembers)
for _, member := range team.Members {
unittest.AssertExistsAndLoadBean(t, &organization.TeamUser{UID: member.ID, TeamID: teamID})
diff --git a/models/packages/descriptor.go b/models/packages/descriptor.go
index 7ffed2d8aa..34f1cad87d 100644
--- a/models/packages/descriptor.go
+++ b/models/packages/descriptor.go
@@ -85,15 +85,15 @@ func GetPackageDescriptor(ctx context.Context, pv *PackageVersion) (*PackageDesc
if err != nil {
return nil, err
}
- o, err := user_model.GetUserByIDCtx(ctx, p.OwnerID)
+ o, err := user_model.GetUserByID(ctx, p.OwnerID)
if err != nil {
return nil, err
}
- repository, err := repo_model.GetRepositoryByIDCtx(ctx, p.RepoID)
+ repository, err := repo_model.GetRepositoryByID(ctx, p.RepoID)
if err != nil && !repo_model.IsErrRepoNotExist(err) {
return nil, err
}
- creator, err := user_model.GetUserByIDCtx(ctx, pv.CreatorID)
+ creator, err := user_model.GetUserByID(ctx, pv.CreatorID)
if err != nil {
return nil, err
}
diff --git a/models/perm/access/access.go b/models/perm/access/access.go
index 55d3f78e01..48ecf78a8c 100644
--- a/models/perm/access/access.go
+++ b/models/perm/access/access.go
@@ -171,7 +171,7 @@ func RecalculateTeamAccesses(ctx context.Context, repo *repo_model.Repository, i
continue
}
- if err = t.GetMembersCtx(ctx); err != nil {
+ if err = t.LoadMembers(ctx); err != nil {
return fmt.Errorf("getMembers '%d': %w", t.ID, err)
}
for _, m := range t.Members {
diff --git a/models/perm/access/repo_permission.go b/models/perm/access/repo_permission.go
index 58c4299d16..88437dc4b2 100644
--- a/models/perm/access/repo_permission.go
+++ b/models/perm/access/repo_permission.go
@@ -364,7 +364,7 @@ func HasAccess(ctx context.Context, userID int64, repo *repo_model.Repository) (
var user *user_model.User
var err error
if userID > 0 {
- user, err = user_model.GetUserByIDCtx(ctx, userID)
+ user, err = user_model.GetUserByID(ctx, userID)
if err != nil {
return false, err
}
diff --git a/models/project/project.go b/models/project/project.go
index 0d655e333e..384f51c5ac 100644
--- a/models/project/project.go
+++ b/models/project/project.go
@@ -338,7 +338,7 @@ func DeleteProjectByIDCtx(ctx context.Context, id int64) error {
return updateRepositoryProjectCount(ctx, p.RepoID)
}
-func DeleteProjectByRepoIDCtx(ctx context.Context, repoID int64) error {
+func DeleteProjectByRepoID(ctx context.Context, repoID int64) error {
switch {
case setting.Database.UseSQLite3:
if _, err := db.GetEngine(ctx).Exec("DELETE FROM project_issue WHERE project_issue.id IN (SELECT project_issue.id FROM project_issue INNER JOIN project WHERE project.id = project_issue.project_id AND project.repo_id = ?)", repoID); err != nil {
diff --git a/models/pull/automerge.go b/models/pull/automerge.go
index d7e04eafa6..f68fb7c681 100644
--- a/models/pull/automerge.go
+++ b/models/pull/automerge.go
@@ -74,7 +74,7 @@ func GetScheduledMergeByPullID(ctx context.Context, pullID int64) (bool, *AutoMe
return false, nil, err
}
- doer, err := user_model.GetUserByIDCtx(ctx, scheduledPRM.DoerID)
+ doer, err := user_model.GetUserByID(ctx, scheduledPRM.DoerID)
if err != nil {
return false, nil, err
}
diff --git a/models/repo.go b/models/repo.go
index ca4f60a2f3..5d333a3aee 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -52,7 +52,7 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error {
sess := db.GetEngine(ctx)
// In case is a organization.
- org, err := user_model.GetUserByIDCtx(ctx, uid)
+ org, err := user_model.GetUserByID(ctx, uid)
if err != nil {
return err
}
@@ -191,7 +191,7 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error {
}
}
- if err := project_model.DeleteProjectByRepoIDCtx(ctx, repoID); err != nil {
+ if err := project_model.DeleteProjectByRepoID(ctx, repoID); err != nil {
return fmt.Errorf("unable to delete projects for repo[%d]: %w", repoID, err)
}
@@ -523,7 +523,7 @@ func CheckRepoStats(ctx context.Context) error {
}
log.Trace("Updating repository count 'num_forks': %d", id)
- repo, err := repo_model.GetRepositoryByID(id)
+ repo, err := repo_model.GetRepositoryByID(ctx, id)
if err != nil {
log.Error("repo_model.GetRepositoryByID[%d]: %v", id, err)
continue
@@ -618,7 +618,7 @@ func DeleteDeployKey(ctx context.Context, doer *user_model.User, id int64) error
// Check if user has access to delete this key.
if !doer.IsAdmin {
- repo, err := repo_model.GetRepositoryByIDCtx(ctx, key.RepoID)
+ repo, err := repo_model.GetRepositoryByID(ctx, key.RepoID)
if err != nil {
return fmt.Errorf("GetRepositoryByID: %w", err)
}
diff --git a/models/repo/collaboration.go b/models/repo/collaboration.go
index 04d92c415f..bd49b9aec9 100644
--- a/models/repo/collaboration.go
+++ b/models/repo/collaboration.go
@@ -44,7 +44,7 @@ func GetCollaborators(ctx context.Context, repoID int64, listOptions db.ListOpti
collaborators := make([]*Collaborator, 0, len(collaborations))
for _, c := range collaborations {
- user, err := user_model.GetUserByIDCtx(ctx, c.UserID)
+ user, err := user_model.GetUserByID(ctx, c.UserID)
if err != nil {
if user_model.IsErrUserNotExist(err) {
log.Warn("Inconsistent DB: User: %d is listed as collaborator of %-v but does not exist", c.UserID, repoID)
diff --git a/models/repo/fork_test.go b/models/repo/fork_test.go
index d02bf91dd9..e8dca204cc 100644
--- a/models/repo/fork_test.go
+++ b/models/repo/fork_test.go
@@ -17,14 +17,14 @@ func TestGetUserFork(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
// User13 has repo 11 forked from repo10
- repo, err := repo_model.GetRepositoryByID(10)
+ repo, err := repo_model.GetRepositoryByID(db.DefaultContext, 10)
assert.NoError(t, err)
assert.NotNil(t, repo)
repo, err = repo_model.GetUserFork(db.DefaultContext, repo.ID, 13)
assert.NoError(t, err)
assert.NotNil(t, repo)
- repo, err = repo_model.GetRepositoryByID(9)
+ repo, err = repo_model.GetRepositoryByID(db.DefaultContext, 9)
assert.NoError(t, err)
assert.NotNil(t, repo)
repo, err = repo_model.GetUserFork(db.DefaultContext, repo.ID, 13)
diff --git a/models/repo/issue.go b/models/repo/issue.go
index 0d27cc041e..e27179caf5 100644
--- a/models/repo/issue.go
+++ b/models/repo/issue.go
@@ -26,7 +26,7 @@ func (repo *Repository) CanEnableTimetracker() bool {
}
// IsTimetrackerEnabled returns whether or not the timetracker is enabled. It returns the default value from config if an error occurs.
-func (repo *Repository) IsTimetrackerEnabled() bool {
+func (repo *Repository) IsTimetrackerEnabled() bool { // Notice: It will be used in template so don't remove directly
return repo.IsTimetrackerEnabledCtx(db.DefaultContext)
}
diff --git a/models/repo/mirror.go b/models/repo/mirror.go
index 63b26b5d0c..2f59b85331 100644
--- a/models/repo/mirror.go
+++ b/models/repo/mirror.go
@@ -52,7 +52,7 @@ func (m *Mirror) GetRepository() *Repository {
return m.Repo
}
var err error
- m.Repo, err = GetRepositoryByIDCtx(db.DefaultContext, m.RepoID)
+ m.Repo, err = GetRepositoryByID(db.DefaultContext, m.RepoID)
if err != nil {
log.Error("getRepositoryByID[%d]: %v", m.ID, err)
}
diff --git a/models/repo/pushmirror.go b/models/repo/pushmirror.go
index 55fde8b838..f79ce59ee2 100644
--- a/models/repo/pushmirror.go
+++ b/models/repo/pushmirror.go
@@ -61,7 +61,7 @@ func (m *PushMirror) GetRepository() *Repository {
return m.Repo
}
var err error
- m.Repo, err = GetRepositoryByIDCtx(db.DefaultContext, m.RepoID)
+ m.Repo, err = GetRepositoryByID(db.DefaultContext, m.RepoID)
if err != nil {
log.Error("getRepositoryByID[%d]: %v", m.ID, err)
}
diff --git a/models/repo/release.go b/models/repo/release.go
index da6235988a..c6cb755344 100644
--- a/models/repo/release.go
+++ b/models/repo/release.go
@@ -93,13 +93,13 @@ func init() {
func (r *Release) LoadAttributes(ctx context.Context) error {
var err error
if r.Repo == nil {
- r.Repo, err = GetRepositoryByIDCtx(ctx, r.RepoID)
+ r.Repo, err = GetRepositoryByID(ctx, r.RepoID)
if err != nil {
return err
}
}
if r.Publisher == nil {
- r.Publisher, err = user_model.GetUserByIDCtx(ctx, r.PublisherID)
+ r.Publisher, err = user_model.GetUserByID(ctx, r.PublisherID)
if err != nil {
if user_model.IsErrUserNotExist(err) {
r.Publisher = user_model.NewGhostUser()
diff --git a/models/repo/repo.go b/models/repo/repo.go
index f58b7de6ed..7cb7138523 100644
--- a/models/repo/repo.go
+++ b/models/repo/repo.go
@@ -315,7 +315,7 @@ func (repo *Repository) LoadUnits(ctx context.Context) (err error) {
}
// UnitEnabled if this repository has the given unit enabled
-func (repo *Repository) UnitEnabled(tp unit.Type) (result bool) {
+func (repo *Repository) UnitEnabled(tp unit.Type) (result bool) { // Notice: Don't remove this function directly, because it has been used in go template.
return repo.UnitEnabledCtx(db.DefaultContext, tp)
}
@@ -390,7 +390,7 @@ func (repo *Repository) GetOwner(ctx context.Context) (err error) {
return nil
}
- repo.Owner, err = user_model.GetUserByIDCtx(ctx, repo.OwnerID)
+ repo.Owner, err = user_model.GetUserByID(ctx, repo.OwnerID)
return err
}
@@ -467,16 +467,12 @@ func (repo *Repository) ComposeDocumentMetas() map[string]string {
// GetBaseRepo populates repo.BaseRepo for a fork repository and
// returns an error on failure (NOTE: no error is returned for
// non-fork repositories, and BaseRepo will be left untouched)
-func (repo *Repository) GetBaseRepo() (err error) {
- return repo.getBaseRepo(db.DefaultContext)
-}
-
-func (repo *Repository) getBaseRepo(ctx context.Context) (err error) {
+func (repo *Repository) GetBaseRepo(ctx context.Context) (err error) {
if !repo.IsFork {
return nil
}
- repo.BaseRepo, err = GetRepositoryByIDCtx(ctx, repo.ForkID)
+ repo.BaseRepo, err = GetRepositoryByID(ctx, repo.ForkID)
return err
}
@@ -611,11 +607,6 @@ func (repo *Repository) GetTrustModel() TrustModelType {
return trustModel
}
-// GetRepositoryByOwnerAndName returns the repository by given ownername and reponame.
-func GetRepositoryByOwnerAndName(ownerName, repoName string) (*Repository, error) {
- return GetRepositoryByOwnerAndNameCtx(db.DefaultContext, ownerName, repoName)
-}
-
// __________ .__ __
// \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
// | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
@@ -647,8 +638,8 @@ func (err ErrRepoNotExist) Unwrap() error {
return util.ErrNotExist
}
-// GetRepositoryByOwnerAndNameCtx returns the repository by given owner name and repo name
-func GetRepositoryByOwnerAndNameCtx(ctx context.Context, ownerName, repoName string) (*Repository, error) {
+// GetRepositoryByOwnerAndName returns the repository by given owner name and repo name
+func GetRepositoryByOwnerAndName(ctx context.Context, ownerName, repoName string) (*Repository, error) {
var repo Repository
has, err := db.GetEngine(ctx).Table("repository").Select("repository.*").
Join("INNER", "`user`", "`user`.id = repository.owner_id").
@@ -678,8 +669,8 @@ func GetRepositoryByName(ownerID int64, name string) (*Repository, error) {
return repo, err
}
-// GetRepositoryByIDCtx returns the repository by given id if exists.
-func GetRepositoryByIDCtx(ctx context.Context, id int64) (*Repository, error) {
+// GetRepositoryByID returns the repository by given id if exists.
+func GetRepositoryByID(ctx context.Context, id int64) (*Repository, error) {
repo := new(Repository)
has, err := db.GetEngine(ctx).ID(id).Get(repo)
if err != nil {
@@ -690,11 +681,6 @@ func GetRepositoryByIDCtx(ctx context.Context, id int64) (*Repository, error) {
return repo, nil
}
-// GetRepositoryByID returns the repository by given id if exists.
-func GetRepositoryByID(id int64) (*Repository, error) {
- return GetRepositoryByIDCtx(db.DefaultContext, id)
-}
-
// GetRepositoriesMapByIDs returns the repositories by given id slice.
func GetRepositoriesMapByIDs(ids []int64) (map[int64]*Repository, error) {
repos := make(map[int64]*Repository, len(ids))
@@ -722,7 +708,7 @@ func GetTemplateRepo(ctx context.Context, repo *Repository) (*Repository, error)
return nil, nil
}
- return GetRepositoryByIDCtx(ctx, repo.TemplateID)
+ return GetRepositoryByID(ctx, repo.TemplateID)
}
// TemplateRepo returns the repository, which is template of this repository
diff --git a/models/repo/repo_test.go b/models/repo/repo_test.go
index 081221d1df..fb473151eb 100644
--- a/models/repo/repo_test.go
+++ b/models/repo/repo_test.go
@@ -115,7 +115,7 @@ func TestMetas(t *testing.T) {
externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleRegexp
testSuccess(markup.IssueNameStyleRegexp)
- repo, err := repo_model.GetRepositoryByID(3)
+ repo, err := repo_model.GetRepositoryByID(db.DefaultContext, 3)
assert.NoError(t, err)
metas = repo.ComposeMetas()
diff --git a/models/repo_collaboration.go b/models/repo_collaboration.go
index 2c04cb442b..b85880eab9 100644
--- a/models/repo_collaboration.go
+++ b/models/repo_collaboration.go
@@ -53,7 +53,7 @@ func DeleteCollaboration(repo *repo_model.Repository, uid int64) (err error) {
}
func reconsiderRepoIssuesAssignee(ctx context.Context, repo *repo_model.Repository, uid int64) error {
- user, err := user_model.GetUserByIDCtx(ctx, uid)
+ user, err := user_model.GetUserByID(ctx, uid)
if err != nil {
return err
}
diff --git a/models/repo_transfer.go b/models/repo_transfer.go
index 6f02ab45fe..362253bdc8 100644
--- a/models/repo_transfer.go
+++ b/models/repo_transfer.go
@@ -41,7 +41,7 @@ func init() {
// LoadAttributes fetches the transfer recipient from the database
func (r *RepoTransfer) LoadAttributes() error {
if r.Recipient == nil {
- u, err := user_model.GetUserByID(r.RecipientID)
+ u, err := user_model.GetUserByID(db.DefaultContext, r.RecipientID)
if err != nil {
return err
}
@@ -65,7 +65,7 @@ func (r *RepoTransfer) LoadAttributes() error {
}
if r.Doer == nil {
- u, err := user_model.GetUserByID(r.DoerID)
+ u, err := user_model.GetUserByID(db.DefaultContext, r.DoerID)
if err != nil {
return err
}
@@ -161,7 +161,7 @@ func CreatePendingRepositoryTransfer(doer, newOwner *user_model.User, repoID int
}
defer committer.Close()
- repo, err := repo_model.GetRepositoryByIDCtx(ctx, repoID)
+ repo, err := repo_model.GetRepositoryByID(ctx, repoID)
if err != nil {
return err
}
diff --git a/models/user/email_address.go b/models/user/email_address.go
index 70394edb23..69e94f8bb6 100644
--- a/models/user/email_address.go
+++ b/models/user/email_address.go
@@ -332,7 +332,7 @@ func ActivateEmail(email *EmailAddress) error {
}
func updateActivation(ctx context.Context, email *EmailAddress, activate bool) error {
- user, err := GetUserByIDCtx(ctx, email.UID)
+ user, err := GetUserByID(ctx, email.UID)
if err != nil {
return err
}
diff --git a/models/user/email_address_test.go b/models/user/email_address_test.go
index 7e523a165d..53fd18c303 100644
--- a/models/user/email_address_test.go
+++ b/models/user/email_address_test.go
@@ -162,7 +162,7 @@ func TestMakeEmailPrimary(t *testing.T) {
err = user_model.MakeEmailPrimary(email)
assert.NoError(t, err)
- user, _ := user_model.GetUserByID(int64(10))
+ user, _ := user_model.GetUserByID(db.DefaultContext, int64(10))
assert.Equal(t, "user101@example.com", user.Email)
}
diff --git a/models/user/user.go b/models/user/user.go
index 915e4243cf..71b036b06f 100644
--- a/models/user/user.go
+++ b/models/user/user.go
@@ -993,12 +993,7 @@ func UserPath(userName string) string { //revive:disable-line:exported
}
// GetUserByID returns the user object by given ID if exists.
-func GetUserByID(id int64) (*User, error) {
- return GetUserByIDCtx(db.DefaultContext, id)
-}
-
-// GetUserByIDCtx returns the user object by given ID if exists.
-func GetUserByIDCtx(ctx context.Context, id int64) (*User, error) {
+func GetUserByID(ctx context.Context, id int64) (*User, error) {
u := new(User)
has, err := db.GetEngine(ctx).ID(id).Get(u)
if err != nil {
@@ -1176,7 +1171,7 @@ func GetUserByEmailContext(ctx context.Context, email string) (*User, error) {
return nil, err
}
if has {
- return GetUserByIDCtx(ctx, emailAddress.UID)
+ return GetUserByID(ctx, emailAddress.UID)
}
// Finally, if email address is the protected email address:
@@ -1220,7 +1215,7 @@ func GetUserByOpenID(uri string) (*User, error) {
return nil, err
}
if has {
- return GetUserByID(oid.UID)
+ return GetUserByID(db.DefaultContext, oid.UID)
}
return nil, ErrUserNotExist{0, uri, 0}
diff --git a/models/user/user_test.go b/models/user/user_test.go
index 2ee4da0d67..525da531f2 100644
--- a/models/user/user_test.go
+++ b/models/user/user_test.go
@@ -22,7 +22,7 @@ import (
func TestOAuth2Application_LoadUser(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
app := unittest.AssertExistsAndLoadBean(t, &auth.OAuth2Application{ID: 1})
- user, err := user_model.GetUserByID(app.UID)
+ user, err := user_model.GetUserByID(db.DefaultContext, app.UID)
assert.NoError(t, err)
assert.NotNil(t, user)
}