Skip to content

Commit c0edac0

Browse files
committed
.
1 parent 7d3657e commit c0edac0

File tree

2 files changed

+10
-34
lines changed

2 files changed

+10
-34
lines changed

pkg/lockdown/lockdown.go

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -104,29 +104,6 @@ func newRepoAccessCache(client *githubv4.Client, opts ...RepoAccessOption) *Repo
104104
return c
105105
}
106106

107-
// SetTTL overrides the default time-to-live used for cache entries. A non-positive
108-
// duration disables expiration.
109-
func (c *RepoAccessCache) SetTTL(ttl time.Duration) {
110-
c.mu.Lock()
111-
defer c.mu.Unlock()
112-
c.ttl = ttl
113-
c.logInfo("repo access cache TTL updated", "ttl", ttl)
114-
115-
// Collect all current entries
116-
entries := make(map[interface{}]*repoAccessCacheEntry)
117-
c.cache.Foreach(func(key interface{}, item *cache2go.CacheItem) {
118-
entries[key] = item.Data().(*repoAccessCacheEntry)
119-
})
120-
121-
// Flush the cache
122-
c.cache.Flush()
123-
124-
// Re-add all entries with the new TTL
125-
for key, entry := range entries {
126-
c.cache.Add(key, ttl, entry)
127-
}
128-
}
129-
130107
// SetLogger updates the logger used for cache diagnostics.
131108
func (c *RepoAccessCache) SetLogger(logger *slog.Logger) {
132109
c.mu.Lock()
@@ -162,25 +139,25 @@ func (c *RepoAccessCache) GetRepoAccessInfo(ctx context.Context, username, owner
162139
c.logDebug("repo access cache hit", "owner", owner, "repo", repo, "user", username)
163140
return entry.isPrivate, cachedHasPush, nil
164141
}
165-
// Entry exists but user not in knownUsers, need to query
142+
c.logDebug("known users cache miss", "owner", owner, "repo", repo, "user", username)
143+
_, hasPush, queryErr := c.queryRepoAccessInfo(ctx, username, owner, repo)
144+
if queryErr != nil {
145+
return false, false, queryErr
146+
}
147+
entry.knownUsers[userKey] = hasPush
148+
c.cache.Add(key, c.ttl, entry)
149+
return entry.isPrivate, entry.knownUsers[userKey], nil
166150
}
151+
167152
c.logDebug("repo access cache miss", "owner", owner, "repo", repo, "user", username)
168153

169154
isPrivate, hasPush, queryErr := c.queryRepoAccessInfo(ctx, username, owner, repo)
170155
if queryErr != nil {
171156
return false, false, queryErr
172157
}
173158

174-
// Repo access info retrieved, update or create cache entry
175-
var entry *repoAccessCacheEntry
176-
if err == nil && cacheItem != nil {
177-
entry = cacheItem.Data().(*repoAccessCacheEntry)
178-
entry.knownUsers[userKey] = hasPush
179-
return entry.isPrivate, entry.knownUsers[userKey], nil
180-
}
181-
182159
// Create new entry
183-
entry = &repoAccessCacheEntry{
160+
entry := &repoAccessCacheEntry{
184161
knownUsers: map[string]bool{userKey: hasPush},
185162
isPrivate: isPrivate,
186163
}

pkg/lockdown/lockdown_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ func newMockRepoAccessCache(t *testing.T, ttl time.Duration) (*RepoAccessCache,
8787
}
8888

8989
func TestRepoAccessCacheEvictsAfterTTL(t *testing.T) {
90-
t.Parallel()
9190
ctx := t.Context()
9291

9392
cache, transport := newMockRepoAccessCache(t, 5*time.Millisecond)

0 commit comments

Comments
 (0)