Auth Proxy: Resolve database is locked errors (#17274)

The change was originally made in #16950, but that change
was too big to cherry pick. This change adds a major database
performance improvement since the number of selects to fetch
a cached item is drastically decreased and by that removes
sqlite database is locked errors.

Fixes #17247
This commit is contained in:
Marcus Efraimsson
2019-05-27 11:16:38 +02:00
parent eda28131ef
commit 1f0e94b633
2 changed files with 13 additions and 12 deletions
+12 -11
View File
@@ -298,23 +298,24 @@ func (auth *AuthProxy) GetSignedUser(userID int64) (*models.SignedInUser, *Error
}
// Remember user in cache
func (auth *AuthProxy) Remember() *Error {
func (auth *AuthProxy) Remember(id int64) *Error {
key := auth.getKey()
// Make sure we do not rewrite the expiration time
if auth.InCache() {
// Check if user already in cache
userID, err := auth.store.Get(key)
if err != nil && err != remotecache.ErrCacheItemNotFound {
return newError("failed to lookup user in cache", err)
}
if userID != nil {
return nil
}
var (
key = auth.getKey()
value, _ = auth.GetUserIDViaCache()
expiration = time.Duration(-auth.cacheTTL) * time.Minute
err = auth.store.Set(key, value, expiration)
)
expiration := time.Duration(-auth.cacheTTL) * time.Minute
err = auth.store.Set(key, id, expiration)
if err != nil {
return newError(err.Error(), nil)
return newError("failed to store user in cache", err)
}
return nil