aboutsummaryrefslogtreecommitdiffstats
path: root/models/avatars/avatar.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-01-05 14:00:32 +0800
committerGitHub <noreply@github.com>2022-01-05 07:00:32 +0100
commit6da078d61690816643f082b2230c0842660bbf4c (patch)
tree935ce41396cdcc6bada1d7c208f420001a55b9e7 /models/avatars/avatar.go
parentec6cc38c6c26f95748be4a9041da2a9528e3625d (diff)
downloadgitea-6da078d61690816643f082b2230c0842660bbf4c.tar.gz
gitea-6da078d61690816643f082b2230c0842660bbf4c.zip
slight optimization for default avatar (#18187)
* slight optimization * Update comment Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'models/avatars/avatar.go')
-rw-r--r--models/avatars/avatar.go23
1 files changed, 16 insertions, 7 deletions
diff --git a/models/avatars/avatar.go b/models/avatars/avatar.go
index 7206a8ae90..6107856ade 100644
--- a/models/avatars/avatar.go
+++ b/models/avatars/avatar.go
@@ -10,6 +10,7 @@ import (
"path"
"strconv"
"strings"
+ "sync"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
@@ -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/