@@ -43,45 +43,6 @@ func newCollaboratorsCache(cacheDir string) *collaboratorsCache {
4343 return cc
4444}
4545
46- // get retrieves a cached collaborators list if it exists and is not expired.
47- //
48- //nolint:unused // Called from graphql_complete.go
49- func (cc * collaboratorsCache ) get (owner , repo string ) (map [string ]string , bool ) {
50- key := fmt .Sprintf ("%s/%s" , owner , repo )
51-
52- cc .mu .RLock ()
53- defer cc .mu .RUnlock ()
54-
55- entry , exists := cc .memory [key ]
56- if ! exists {
57- return nil , false
58- }
59-
60- // Check if cache entry is expired
61- if time .Since (entry .CachedAt ) > collaboratorsCacheDuration {
62- return nil , false
63- }
64-
65- return entry .Collaborators , true
66- }
67-
68- // set stores a collaborators list in the cache.
69- //
70- //nolint:unused // Called from graphql_complete.go
71- func (cc * collaboratorsCache ) set (owner , repo string , collaborators map [string ]string ) error {
72- key := fmt .Sprintf ("%s/%s" , owner , repo )
73-
74- cc .mu .Lock ()
75- cc .memory [key ] = collaboratorsEntry {
76- Collaborators : collaborators ,
77- CachedAt : time .Now (),
78- }
79- cc .mu .Unlock ()
80-
81- // Save to disk after releasing the lock
82- return cc .saveToDisk ()
83- }
84-
8546// loadFromDisk loads the cache from disk.
8647func (cc * collaboratorsCache ) loadFromDisk () error {
8748 // Skip if no disk path is set (in-memory only mode)
@@ -114,38 +75,3 @@ func (cc *collaboratorsCache) loadFromDisk() error {
11475
11576 return nil
11677}
117-
118- // saveToDisk saves the current cache to disk.
119- //
120- //nolint:unused // Called from set()
121- func (cc * collaboratorsCache ) saveToDisk () error {
122- // Skip if no disk path is set (in-memory only mode)
123- if cc .diskPath == "" {
124- return nil
125- }
126-
127- // Create a copy to avoid holding the lock during I/O
128- cc .mu .RLock ()
129- cacheCopy := make (map [string ]collaboratorsEntry , len (cc .memory ))
130- for k , v := range cc .memory {
131- cacheCopy [k ] = v
132- }
133- cc .mu .RUnlock ()
134-
135- data , err := json .Marshal (cacheCopy )
136- if err != nil {
137- return fmt .Errorf ("marshaling collaborators cache: %w" , err )
138- }
139-
140- // Write to temp file first, then rename for atomicity
141- tempFile := cc .diskPath + ".tmp"
142- if err := os .WriteFile (tempFile , data , 0o600 ); err != nil {
143- return fmt .Errorf ("writing collaborators cache: %w" , err )
144- }
145-
146- if err := os .Rename (tempFile , cc .diskPath ); err != nil {
147- return fmt .Errorf ("renaming collaborators cache: %w" , err )
148- }
149-
150- return nil
151- }
0 commit comments