Skip to content

Commit cbe1813

Browse files
committed
simpilfy
1 parent f66e77b commit cbe1813

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

models/system/setting.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,16 @@ func (d *dbConfigCachedGetter) GetValue(ctx context.Context, key string) (v stri
115115

116116
func (d *dbConfigCachedGetter) GetRevision(ctx context.Context) int {
117117
d.mu.RLock()
118-
defer d.mu.RUnlock()
119-
if time.Since(d.cacheTime) < time.Second {
120-
return d.revision
121-
}
118+
cachedDuration := time.Since(d.cacheTime)
119+
cachedRevision := d.revision
122120
d.mu.RUnlock()
121+
122+
if cachedDuration < time.Second {
123+
return cachedRevision
124+
}
125+
123126
d.mu.Lock()
127+
defer d.mu.Unlock()
124128
if GetRevision(ctx) != d.revision {
125129
rev, set, err := GetAllSettings(ctx)
126130
if err != nil {
@@ -131,8 +135,6 @@ func (d *dbConfigCachedGetter) GetRevision(ctx context.Context) int {
131135
}
132136
}
133137
d.cacheTime = time.Now()
134-
d.mu.Unlock()
135-
d.mu.RLock()
136138
return d.revision
137139
}
138140

0 commit comments

Comments
 (0)