Skip to content

Commit

Permalink
slight optimization for default avatar (#18187)
Browse files Browse the repository at this point in the history
* slight optimization

* Update comment

Co-authored-by: 6543 <6543@obermui.de>
  • Loading branch information
lunny and 6543 authored Jan 5, 2022
1 parent ec6cc38 commit 6da078d
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions models/avatars/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path"
"strconv"
"strings"
"sync"

"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
Expand All @@ -31,16 +32,24 @@ func init() {
db.RegisterModel(new(EmailHash))
}

var (
defaultAvatarLink string
once sync.Once
)

// DefaultAvatarLink the default avatar link
func DefaultAvatarLink() string {
u, err := url.Parse(setting.AppSubURL)
if err != nil {
log.Error("GetUserByEmail: %v", err)
return ""
}
once.Do(func() {
u, err := url.Parse(setting.AppSubURL)
if err != nil {
log.Error("Can not parse AppSubURL: %v", err)
return
}

u.Path = path.Join(u.Path, "/assets/img/avatar_default.png")
return u.String()
u.Path = path.Join(u.Path, "/assets/img/avatar_default.png")
defaultAvatarLink = u.String()
})
return defaultAvatarLink
}

// HashEmail hashes email address to MD5 string. https://en.gravatar.com/site/implement/hash/
Expand Down

0 comments on commit 6da078d

Please sign in to comment.