Fix database lock when use random repository fallback image (#7166)

* fix database lock when use random repository fallback image

* remove unused function
This commit is contained in:
Lunny Xiao 2019-06-12 08:12:13 +08:00 committed by techknowlogick
parent 1608f63e39
commit 5832f8d90d

View File

@ -331,7 +331,7 @@ func (repo *Repository) innerAPIFormat(e Engine, mode AccessMode, isParent bool)
AllowRebase: allowRebase, AllowRebase: allowRebase,
AllowRebaseMerge: allowRebaseMerge, AllowRebaseMerge: allowRebaseMerge,
AllowSquash: allowSquash, AllowSquash: allowSquash,
AvatarURL: repo.AvatarLink(), AvatarURL: repo.avatarLink(e),
} }
} }
@ -2528,11 +2528,7 @@ func (repo *Repository) CustomAvatarPath() string {
return filepath.Join(setting.RepositoryAvatarUploadPath, repo.Avatar) return filepath.Join(setting.RepositoryAvatarUploadPath, repo.Avatar)
} }
// GenerateRandomAvatar generates a random avatar for repository. // generateRandomAvatar generates a random avatar for repository.
func (repo *Repository) GenerateRandomAvatar() error {
return repo.generateRandomAvatar(x)
}
func (repo *Repository) generateRandomAvatar(e Engine) error { func (repo *Repository) generateRandomAvatar(e Engine) error {
idToString := fmt.Sprintf("%d", repo.ID) idToString := fmt.Sprintf("%d", repo.ID)
@ -2585,7 +2581,10 @@ func RemoveRandomAvatars() error {
// RelAvatarLink returns a relative link to the repository's avatar. // RelAvatarLink returns a relative link to the repository's avatar.
func (repo *Repository) RelAvatarLink() string { func (repo *Repository) RelAvatarLink() string {
return repo.relAvatarLink(x)
}
func (repo *Repository) relAvatarLink(e Engine) string {
// If no avatar - path is empty // If no avatar - path is empty
avatarPath := repo.CustomAvatarPath() avatarPath := repo.CustomAvatarPath()
if len(avatarPath) <= 0 || !com.IsFile(avatarPath) { if len(avatarPath) <= 0 || !com.IsFile(avatarPath) {
@ -2593,8 +2592,8 @@ func (repo *Repository) RelAvatarLink() string {
case "image": case "image":
return setting.RepositoryAvatarFallbackImage return setting.RepositoryAvatarFallbackImage
case "random": case "random":
if err := repo.GenerateRandomAvatar(); err != nil { if err := repo.generateRandomAvatar(e); err != nil {
log.Error("GenerateRandomAvatar: %v", err) log.Error("generateRandomAvatar: %v", err)
} }
default: default:
// default behaviour: do not display avatar // default behaviour: do not display avatar
@ -2604,9 +2603,9 @@ func (repo *Repository) RelAvatarLink() string {
return setting.AppSubURL + "/repo-avatars/" + repo.Avatar return setting.AppSubURL + "/repo-avatars/" + repo.Avatar
} }
// AvatarLink returns user avatar absolute link. // avatarLink returns user avatar absolute link.
func (repo *Repository) AvatarLink() string { func (repo *Repository) avatarLink(e Engine) string {
link := repo.RelAvatarLink() link := repo.relAvatarLink(e)
// link may be empty! // link may be empty!
if len(link) > 0 { if len(link) > 0 {
if link[0] == '/' && link[1] != '/' { if link[0] == '/' && link[1] != '/' {