Add debug log

This commit is contained in:
kolaente 2020-08-01 20:09:49 +02:00
parent 0c35536e36
commit 03edcd511d
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 5 additions and 0 deletions

View File

@ -17,6 +17,7 @@
package initials
import (
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/user"
"github.com/disintegration/imaging"
"strconv"
@ -123,6 +124,7 @@ func getAvatarForUser(u *user.User) (fullSizeAvatar *image.RGBA64, err error) {
var cached bool
fullSizeAvatar, cached = cache[u.ID]
if !cached {
log.Debugf("Initials avatar for user %d not cached, creating...", u.ID)
firstRune := []rune(strings.ToUpper(u.Username))[0]
bg := avatarBgColors[int(u.ID)%len(avatarBgColors)] // Random color based on the user id
@ -142,6 +144,7 @@ func (p *Provider) GetAvatar(u *user.User, size int64) (avatar []byte, mimeType
cacheKey := strconv.Itoa(int(u.ID)) + "_" + strconv.Itoa(int(size))
avatar, cached = cacheResized[cacheKey]
if !cached {
log.Debugf("Initials avatar for user %d and size %d not cached, creating...", u.ID, size)
fullAvatar, err := getAvatarForUser(u)
if err != nil {
return nil, "", err
@ -155,6 +158,8 @@ func (p *Provider) GetAvatar(u *user.User, size int64) (avatar []byte, mimeType
}
avatar = buf.Bytes()
cacheResized[cacheKey] = avatar
} else {
log.Debugf("Serving initials avatar for user %d and size %d from cache", u.ID, size)
}
return avatar, "image/png", err