summaryrefslogtreecommitdiffstats
path: root/models/user_avatar.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-11-21 23:41:00 +0800
committerGitHub <noreply@github.com>2021-11-21 23:41:00 +0800
commitd710af6669654f27f02b69d7ef1ba563e7d58a90 (patch)
tree9727f468a570106293dc90beb70035180bbb7e8e /models/user_avatar.go
parent0add627182388ac63fd04b94cdf912fb87fd0326 (diff)
downloadgitea-d710af6669654f27f02b69d7ef1ba563e7d58a90.tar.gz
gitea-d710af6669654f27f02b69d7ef1ba563e7d58a90.zip
Remove NewSession method from db.Engine interface (#17577)
* Remove NewSession method from db.Engine interface * Fix bug * Some improvements * Fix bug * Fix test * Use XXXBean instead of XXXExample
Diffstat (limited to 'models/user_avatar.go')
-rw-r--r--models/user_avatar.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/models/user_avatar.go b/models/user_avatar.go
index f96f66f930..50998514e0 100644
--- a/models/user_avatar.go
+++ b/models/user_avatar.go
@@ -109,11 +109,11 @@ func (u *User) UploadAvatar(data []byte) error {
return err
}
- sess := db.NewSession(db.DefaultContext)
- defer sess.Close()
- if err = sess.Begin(); err != nil {
+ ctx, committer, err := db.TxContext()
+ if err != nil {
return err
}
+ defer committer.Close()
u.UseCustomAvatar = true
// Different users can upload same image as avatar
@@ -121,7 +121,7 @@ func (u *User) UploadAvatar(data []byte) error {
// Otherwise, if any of the users delete his avatar
// Other users will lose their avatars too.
u.Avatar = fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%d-%x", u.ID, md5.Sum(data)))))
- if err = updateUserCols(sess, u, "use_custom_avatar", "avatar"); err != nil {
+ if err = updateUserCols(db.GetEngine(ctx), u, "use_custom_avatar", "avatar"); err != nil {
return fmt.Errorf("updateUser: %v", err)
}
@@ -134,7 +134,7 @@ func (u *User) UploadAvatar(data []byte) error {
return fmt.Errorf("Failed to create dir %s: %v", u.CustomAvatarRelativePath(), err)
}
- return sess.Commit()
+ return committer.Commit()
}
// IsUploadAvatarChanged returns true if the current user's avatar would be changed with the provided data