mirror of
https://github.com/go-gitea/gitea
synced 2025-07-03 09:07:19 +00:00
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>
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user