mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-01 04:12:10 +00:00
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>
This commit is contained in:
parent
462306e263
commit
a4bfef265d
335 changed files with 4191 additions and 3654 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue