Skip to content

Commit

Permalink
simpilfy
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Nov 16, 2023
1 parent f66e77b commit c2d73ff
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions models/system/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,16 @@ 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
}
cacheTimeDur := time.Since(d.cacheTime)
cachedVRevision := d.revision
d.mu.RUnlock()

if cacheTimeDur < time.Second {
return cachedVRevision
}

d.mu.Lock()
defer d.mu.Unlock()
if GetRevision(ctx) != d.revision {
rev, set, err := GetAllSettings(ctx)
if err != nil {
Expand All @@ -131,8 +135,6 @@ func (d *dbConfigCachedGetter) GetRevision(ctx context.Context) int {
}
}
d.cacheTime = time.Now()
d.mu.Unlock()
d.mu.RLock()
return d.revision
}

Expand Down

0 comments on commit c2d73ff

Please sign in to comment.