aboutsummaryrefslogtreecommitdiffstats
path: root/models/repo_avatar.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-09-19 19:49:59 +0800
committerGitHub <noreply@github.com>2021-09-19 19:49:59 +0800
commita4bfef265d9e512830350635a0489c2cdcd6508f (patch)
tree1e3c2ec94276dfcb2f8ba73a2ac075ba39c4a34a /models/repo_avatar.go
parent462306e263db5a809dbe2cdf62e99307aeff28de (diff)
downloadgitea-a4bfef265d9e512830350635a0489c2cdcd6508f.tar.gz
gitea-a4bfef265d9e512830350635a0489c2cdcd6508f.zip
Move db related basic functions to models/db (#17075)
* Move db related basic functions to models/db * Fix lint * Fix lint * Fix test * Fix lint * Fix lint * revert unnecessary change * Fix test * Fix wrong replace string * Use *Context * Correct committer spelling and fix wrong replaced words Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models/repo_avatar.go')
-rw-r--r--models/repo_avatar.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/models/repo_avatar.go b/models/repo_avatar.go
index 6f8f55f9e3..8133cdc706 100644
--- a/models/repo_avatar.go
+++ b/models/repo_avatar.go
@@ -13,6 +13,7 @@ import (
"strconv"
"strings"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/avatar"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -25,7 +26,7 @@ func (repo *Repository) CustomAvatarRelativePath() string {
}
// generateRandomAvatar generates a random avatar for repository.
-func (repo *Repository) generateRandomAvatar(e Engine) error {
+func (repo *Repository) generateRandomAvatar(e db.Engine) error {
idToString := fmt.Sprintf("%d", repo.ID)
seed := idToString
@@ -56,7 +57,7 @@ func (repo *Repository) generateRandomAvatar(e Engine) error {
// RemoveRandomAvatars removes the randomly generated avatars that were created for repositories
func RemoveRandomAvatars(ctx context.Context) error {
- return x.
+ return db.DefaultContext().Engine().
Where("id > 0").BufferSize(setting.Database.IterateBufferSize).
Iterate(new(Repository),
func(idx int, bean interface{}) error {
@@ -76,10 +77,10 @@ func RemoveRandomAvatars(ctx context.Context) error {
// RelAvatarLink returns a relative link to the repository's avatar.
func (repo *Repository) RelAvatarLink() string {
- return repo.relAvatarLink(x)
+ return repo.relAvatarLink(db.DefaultContext().Engine())
}
-func (repo *Repository) relAvatarLink(e Engine) string {
+func (repo *Repository) relAvatarLink(e db.Engine) string {
// If no avatar - path is empty
avatarPath := repo.CustomAvatarRelativePath()
if len(avatarPath) == 0 {
@@ -100,11 +101,11 @@ func (repo *Repository) relAvatarLink(e Engine) string {
// AvatarLink returns a link to the repository's avatar.
func (repo *Repository) AvatarLink() string {
- return repo.avatarLink(x)
+ return repo.avatarLink(db.DefaultContext().Engine())
}
// avatarLink returns user avatar absolute link.
-func (repo *Repository) avatarLink(e Engine) string {
+func (repo *Repository) avatarLink(e db.Engine) string {
link := repo.relAvatarLink(e)
// link may be empty!
if len(link) > 0 {
@@ -128,7 +129,7 @@ func (repo *Repository) UploadAvatar(data []byte) error {
return nil
}
- sess := x.NewSession()
+ sess := db.DefaultContext().NewSession()
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
@@ -171,7 +172,7 @@ func (repo *Repository) DeleteAvatar() error {
avatarPath := repo.CustomAvatarRelativePath()
log.Trace("DeleteAvatar[%d]: %s", repo.ID, avatarPath)
- sess := x.NewSession()
+ sess := db.DefaultContext().NewSession()
defer sess.Close()
if err := sess.Begin(); err != nil {
return err