1
0

Change keyvalue.Get to return if a value exists or not instead of an error

This commit is contained in:
kolaente
2021-01-31 12:32:46 +01:00
parent fe72f30b24
commit 2e88600c93
9 changed files with 28 additions and 43 deletions

View File

@ -26,7 +26,6 @@ import (
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/modules/keyvalue"
e "code.vikunja.io/api/pkg/modules/keyvalue/error"
"code.vikunja.io/api/pkg/user"
"github.com/disintegration/imaging"
)
@ -40,8 +39,8 @@ func (p *Provider) GetAvatar(u *user.User, size int64) (avatar []byte, mimeType
cacheKey := "avatar_upload_" + strconv.Itoa(int(u.ID))
ai, err := keyvalue.Get(cacheKey)
if err != nil && !e.IsErrValueNotFoundForKey(err) {
ai, exists, err := keyvalue.Get(cacheKey)
if err != nil {
return nil, "", err
}
@ -51,7 +50,7 @@ func (p *Provider) GetAvatar(u *user.User, size int64) (avatar []byte, mimeType
cached = ai.(map[int64][]byte)
}
if err != nil && e.IsErrValueNotFoundForKey(err) {
if !exists {
// Nothing ever cached for this user so we need to create the size map to avoid panics
cached = make(map[int64][]byte)
} else {