diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-12-03 10:48:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-03 10:48:26 +0800 |
commit | 0a7d3ff786508284224ada17956a65bb759d9265 (patch) | |
tree | 4860fca95c1432ab59c6723ee2b053b1c7d6779d /models/activities/action.go | |
parent | 8698458f48eafeab21014db544aa7160368856e1 (diff) | |
download | gitea-0a7d3ff786508284224ada17956a65bb759d9265.tar.gz gitea-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/activities/action.go')
-rw-r--r-- | models/activities/action.go | 22 |
1 files changed, 11 insertions, 11 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 |