Add config option for caching avatars

This commit is contained in:
kolaente 2020-03-01 20:47:01 +01:00
parent 4aa28b05f2
commit 6861e55e89
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
4 changed files with 8 additions and 1 deletions

View File

@ -30,6 +30,8 @@ service:
timezone: GMT
# Whether task comments should be enabled or not
enabletaskcomments: true
# The duration in seconds until a cached gravatar user avatar expires
gravatarexpiration: 3600
database:
# Database type to use. Supported types are mysql, postgres and sqlite.

View File

@ -73,6 +73,8 @@ service:
timezone: GMT
# Whether task comments should be enabled or not
enabletaskcomments: true
# The duration in seconds until a cached gravatar user avatar expires
gravatarexpiration: 3600
database:
# Database type to use. Supported types are mysql, postgres and sqlite.

View File

@ -46,6 +46,7 @@ const (
ServiceEnableTaskAttachments Key = `service.enabletaskattachments`
ServiceTimeZone Key = `service.timezone`
ServiceEnableTaskComments Key = `service.enabletaskcomments`
ServiceGravatarExpiration Key = `service.gravatarexpiration`
DatabaseType Key = `database.type`
DatabaseHost Key = `database.host`
@ -173,6 +174,7 @@ func InitDefaultConfig() {
ServiceEnableTaskAttachments.setDefault(true)
ServiceTimeZone.setDefault("GMT")
ServiceEnableTaskComments.setDefault(true)
ServiceGravatarExpiration.setDefault(3600)
// Database
DatabaseType.setDefault("sqlite")

View File

@ -17,6 +17,7 @@
package gravatar
import (
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/user"
"io/ioutil"
@ -51,7 +52,7 @@ func (g *Provider) GetAvatar(user *user.User, size int64) ([]byte, string, error
// elaped is alway < 0 so the next check would always succeed.
// To have it make sense, we flip that.
elapsed := a.loadedAt.Sub(time.Now()) * -1
needsRefetch = elapsed > 10*time.Second
needsRefetch = elapsed > time.Duration(config.ServiceGravatarExpiration.GetInt64())*time.Second
if needsRefetch {
log.Debugf("Refetching avatar for user %d after %v", user.ID, elapsed)
} else {