diff options
author | Unknwon <u@gogs.io> | 2015-11-13 16:43:43 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-11-13 16:43:43 -0500 |
commit | 1559bd58e7dee6927d31e1aaf1b6ebfc0ffd59dc (patch) | |
tree | 1051e333cd223539788306aa169899b8c332d69a /routers/user | |
parent | 6a664e88c77f1ddd9c5bff4898e21a8271a5da9a (diff) | |
download | gitea-1559bd58e7dee6927d31e1aaf1b6ebfc0ffd59dc.tar.gz gitea-1559bd58e7dee6927d31e1aaf1b6ebfc0ffd59dc.zip |
save custom avatar as PNG
Diffstat (limited to 'routers/user')
-rw-r--r-- | routers/user/home.go | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/routers/user/home.go b/routers/user/home.go index c5c42694fa..fc94dfc9e2 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -111,6 +111,7 @@ func Dashboard(ctx *middleware.Context) { // Check access of private repositories. feeds := make([]*models.Action, 0, len(actions)) + unameAvatars := make(map[string]string) for _, act := range actions { if act.IsPrivate { // This prevents having to retrieve the repository for each action @@ -122,16 +123,22 @@ func Dashboard(ctx *middleware.Context) { } } - // FIXME: cache results? - u, err := models.GetUserByName(act.ActUserName) - if err != nil { - if models.IsErrUserNotExist(err) { - continue + + // Cache results to reduce queries. + _, ok := unameAvatars[act.ActUserName] + if !ok { + u, err := models.GetUserByName(act.ActUserName) + if err != nil { + if models.IsErrUserNotExist(err) { + continue + } + ctx.Handle(500, "GetUserByName", err) + return } - ctx.Handle(500, "GetUserByName", err) - return + unameAvatars[act.ActUserName] = u.AvatarLink() } - act.ActAvatar = u.AvatarLink() + + act.ActAvatar = unameAvatars[act.ActUserName] feeds = append(feeds, act) } ctx.Data["Feeds"] = feeds |