Skip to content

Commit fce1d5d

Browse files
authored
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
1 parent 49dddd8 commit fce1d5d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

models/system/setting.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,24 +115,26 @@ 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
118+
cachedDuration := time.Since(d.cacheTime)
119+
cachedRevision := d.revision
120+
d.mu.RUnlock()
121+
122+
if cachedDuration < time.Second {
123+
return cachedRevision
121124
}
125+
126+
d.mu.Lock()
127+
defer d.mu.Unlock()
122128
if GetRevision(ctx) != d.revision {
123-
d.mu.RUnlock()
124-
d.mu.Lock()
125129
rev, set, err := GetAllSettings(ctx)
126130
if err != nil {
127131
log.Error("Unable to get all settings: %v", err)
128132
} else {
129-
d.cacheTime = time.Now()
130133
d.revision = rev
131134
d.settings = set
132135
}
133-
d.mu.Unlock()
134-
d.mu.RLock()
135136
}
137+
d.cacheTime = time.Now()
136138
return d.revision
137139
}
138140

0 commit comments

Comments
 (0)