Add config option for caching avatars
This commit is contained in:
parent
4aa28b05f2
commit
6861e55e89
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue