diff options
author | JakobDev <jakobdev@gmx.de> | 2023-10-11 06:24:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-11 04:24:07 +0000 |
commit | ebe803e514acb4eedc884226be2489ee6b4acd28 (patch) | |
tree | 3f4d38f8267142dcd0e8df7d76cd4fe04c47b85e /services/user | |
parent | 50166d1f7c6df41c79561b094e29c9698c0000d5 (diff) | |
download | gitea-ebe803e514acb4eedc884226be2489ee6b4acd28.tar.gz gitea-ebe803e514acb4eedc884226be2489ee6b4acd28.zip |
Penultimate round of `db.DefaultContext` refactor (#27414)
Part of #27065
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'services/user')
-rw-r--r-- | services/user/avatar.go | 9 | ||||
-rw-r--r-- | services/user/user.go | 2 |
2 files changed, 6 insertions, 5 deletions
diff --git a/services/user/avatar.go b/services/user/avatar.go index 26c100abdb..4130d07c38 100644 --- a/services/user/avatar.go +++ b/services/user/avatar.go @@ -4,6 +4,7 @@ package user import ( + "context" "fmt" "io" @@ -15,13 +16,13 @@ import ( ) // UploadAvatar saves custom avatar for user. -func UploadAvatar(u *user_model.User, data []byte) error { +func UploadAvatar(ctx context.Context, u *user_model.User, data []byte) error { avatarData, err := avatar.ProcessAvatarImage(data) if err != nil { return err } - ctx, committer, err := db.TxContext(db.DefaultContext) + ctx, committer, err := db.TxContext(ctx) if err != nil { return err } @@ -44,7 +45,7 @@ func UploadAvatar(u *user_model.User, data []byte) error { } // DeleteAvatar deletes the user's custom avatar. -func DeleteAvatar(u *user_model.User) error { +func DeleteAvatar(ctx context.Context, u *user_model.User) error { aPath := u.CustomAvatarRelativePath() log.Trace("DeleteAvatar[%d]: %s", u.ID, aPath) if len(u.Avatar) > 0 { @@ -55,7 +56,7 @@ func DeleteAvatar(u *user_model.User) error { u.UseCustomAvatar = false u.Avatar = "" - if _, err := db.GetEngine(db.DefaultContext).ID(u.ID).Cols("avatar, use_custom_avatar").Update(u); err != nil { + if _, err := db.GetEngine(ctx).ID(u.ID).Cols("avatar, use_custom_avatar").Update(u); err != nil { return fmt.Errorf("UpdateUser: %w", err) } return nil diff --git a/services/user/user.go b/services/user/user.go index 53cc361107..b95a7e0639 100644 --- a/services/user/user.go +++ b/services/user/user.go @@ -223,7 +223,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error { } } - ctx, committer, err := db.TxContext(db.DefaultContext) + ctx, committer, err := db.TxContext(ctx) if err != nil { return err } |