Skip to content

Commit

Permalink
Fix system config cache expiration timing (#28072)
Browse files Browse the repository at this point in the history
To avoid unnecessary database access, the `cacheTime` should always be
set if the revision has been checked.

Fix #28057
  • Loading branch information
wxiaoguang authored Nov 16, 2023
1 parent 49dddd8 commit fce1d5d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions models/system/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit fce1d5d

Please sign in to comment.