Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b7d64db

Browse files
committed
improve clarity
1 parent 84d9556 commit b7d64db

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

coderd/cryptokeys/dbkeycache.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,19 @@ func (d *DBKeyCache) Version(ctx context.Context, sequence int32) (database.Cryp
9898

9999
func (d *DBKeyCache) Latest(ctx context.Context) (database.CryptoKey, error) {
100100
d.cacheMu.RLock()
101+
latest := d.latestKey
102+
d.cacheMu.RUnlock()
103+
101104
now := d.Clock.Now().UTC()
102-
if d.latestKey.IsActive(now) {
103-
d.cacheMu.RUnlock()
104-
return d.latestKey, nil
105+
if latest.IsActive(now) {
106+
return latest, nil
105107
}
106-
d.cacheMu.RUnlock()
107108

108109
d.cacheMu.Lock()
109110
defer d.cacheMu.Unlock()
110111

111-
if d.latestKey.IsActive(now) {
112-
return d.latestKey, nil
112+
if latest.IsActive(now) {
113+
return latest, nil
113114
}
114115

115116
cache, latest, err := d.newCache(ctx)
@@ -153,6 +154,7 @@ func (d *DBKeyCache) newCache(ctx context.Context) (map[int32]database.CryptoKey
153154
}
154155
cache := toMap(keys)
155156
var latest database.CryptoKey
157+
// Keys are returned in order from highest sequence to lowest.
156158
for _, key := range keys {
157159
if !key.IsActive(now) {
158160
continue

0 commit comments

Comments
 (0)