diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-11-16 20:53:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-16 12:53:42 +0000 |
commit | fce1d5d7dce6a16429d0fe043555eac2c083ae7b (patch) | |
tree | d60fc6648f1b77bd284e21176d55d84a9e3076a6 /models/system/setting.go | |
parent | 49dddd87b19aebe83e1c54a455e62529a19f61b4 (diff) | |
download | gitea-fce1d5d7dce6a16429d0fe043555eac2c083ae7b.tar.gz gitea-fce1d5d7dce6a16429d0fe043555eac2c083ae7b.zip |
Fix system config cache expiration timing (#28072)
To avoid unnecessary database access, the `cacheTime` should always be
set if the revision has been checked.
Fix #28057
Diffstat (limited to 'models/system/setting.go')
-rw-r--r-- | models/system/setting.go | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/models/system/setting.go b/models/system/setting.go index 1ae6f5c652..507d23cff6 100644 --- a/models/system/setting.go +++ b/models/system/setting.go @@ -115,24 +115,26 @@ func (d *dbConfigCachedGetter) GetValue(ctx context.Context, key string) (v stri func (d *dbConfigCachedGetter) GetRevision(ctx context.Context) int { d.mu.RLock() - defer d.mu.RUnlock() - if time.Since(d.cacheTime) < time.Second { - return d.revision + cachedDuration := time.Since(d.cacheTime) + cachedRevision := d.revision + d.mu.RUnlock() + + if cachedDuration < time.Second { + return cachedRevision } + + d.mu.Lock() + defer d.mu.Unlock() if GetRevision(ctx) != d.revision { - d.mu.RUnlock() - d.mu.Lock() rev, set, err := GetAllSettings(ctx) if err != nil { log.Error("Unable to get all settings: %v", err) } else { - d.cacheTime = time.Now() d.revision = rev d.settings = set } - d.mu.Unlock() - d.mu.RLock() } + d.cacheTime = time.Now() return d.revision } |