77 "encoding/json"
88 "errors"
99 "fmt"
10- "log/slog"
1110 "time"
1211
1312 "github.com/codeGROOVE-dev/bdcache"
@@ -28,11 +27,11 @@ type persister[K comparable, V any] struct {
2827// ValidateKey checks if a key is valid for Datastore persistence.
2928// Datastore has stricter key length limits than files.
3029func (* persister [K , V ]) ValidateKey (key K ) error {
31- keyStr := fmt .Sprintf ("%v" , key )
32- if len (keyStr ) > maxDatastoreKeyLen {
33- return fmt .Errorf ("key too long: %d bytes (max %d for datastore)" , len (keyStr ), maxDatastoreKeyLen )
30+ s := fmt .Sprintf ("%v" , key )
31+ if len (s ) > maxDatastoreKeyLen {
32+ return fmt .Errorf ("key too long: %d bytes (max %d for datastore)" , len (s ), maxDatastoreKeyLen )
3433 }
35- if keyStr == "" {
34+ if s == "" {
3635 return errors .New ("key cannot be empty" )
3736 }
3837 return nil
@@ -67,8 +66,6 @@ func New[K comparable, V any](ctx context.Context, cacheID string) (bdcache.Pers
6766 // Verify connectivity (assert readiness)
6867 // Note: ds9 doesn't expose Ping, but client creation validates connectivity
6968
70- slog .Debug ("initialized datastore persistence" , "database" , cacheID , "kind" , datastoreKind )
71-
7269 return & persister [K , V ]{
7370 client : client ,
7471 kind : datastoreKind ,
@@ -78,8 +75,7 @@ func New[K comparable, V any](ctx context.Context, cacheID string) (bdcache.Pers
7875// makeKey creates a Datastore key from a cache key.
7976// We use the string representation directly as the key name.
8077func (p * persister [K , V ]) makeKey (key K ) * ds.Key {
81- keyStr := fmt .Sprintf ("%v" , key )
82- return ds .NameKey (p .kind , keyStr , nil )
78+ return ds .NameKey (p .kind , fmt .Sprintf ("%v" , key ), nil )
8379}
8480
8581// Load retrieves a value from Datastore.
@@ -168,10 +164,7 @@ func (p *persister[K, V]) LoadRecent(ctx context.Context, limit int) (entries <-
168164 }
169165
170166 iter := p .client .Run (ctx , query )
171-
172167 now := time .Now ()
173- loaded := 0
174- expired := 0
175168
176169 for {
177170 var entry datastoreEntry
@@ -194,7 +187,6 @@ func (p *persister[K, V]) LoadRecent(ctx context.Context, limit int) (entries <-
194187
195188 // Skip expired entries - cleanup is handled by native TTL or periodic Cleanup() calls
196189 if ! entry .Expiry .IsZero () && now .After (entry .Expiry ) {
197- expired ++
198190 continue
199191 }
200192
@@ -207,10 +199,6 @@ func (p *persister[K, V]) LoadRecent(ctx context.Context, limit int) (entries <-
207199 // If Sscanf fails, try direct type assertion for string keys
208200 sk , ok := any (ks ).(K )
209201 if ! ok {
210- slog .Warn ("failed to parse key from datastore" ,
211- "keyStr" , ks ,
212- "expectedType" , fmt .Sprintf ("%T" , key ),
213- "error" , err )
214202 continue
215203 }
216204 key = sk
@@ -219,18 +207,11 @@ func (p *persister[K, V]) LoadRecent(ctx context.Context, limit int) (entries <-
219207 // Decode value from base64
220208 vb , err := base64 .StdEncoding .DecodeString (entry .Value )
221209 if err != nil {
222- slog .Warn ("failed to decode value from datastore" ,
223- "key" , ks ,
224- "error" , err )
225210 continue
226211 }
227212
228213 var value V
229214 if err := json .Unmarshal (vb , & value ); err != nil {
230- slog .Warn ("failed to unmarshal value from datastore" ,
231- "key" , ks ,
232- "valueLength" , len (vb ),
233- "error" , err )
234215 continue
235216 }
236217
@@ -240,10 +221,7 @@ func (p *persister[K, V]) LoadRecent(ctx context.Context, limit int) (entries <-
240221 Expiry : entry .Expiry ,
241222 UpdatedAt : entry .UpdatedAt ,
242223 }
243- loaded ++
244224 }
245-
246- slog .Info ("loaded cache entries from datastore" , "loaded" , loaded , "expired" , expired )
247225 }()
248226
249227 return entryCh , errCh
@@ -277,7 +255,6 @@ func (p *persister[K, V]) Cleanup(ctx context.Context, maxAge time.Duration) (in
277255 return 0 , fmt .Errorf ("delete expired entries: %w" , err )
278256 }
279257
280- slog .Info ("cleaned up expired entries" , "count" , len (keys ), "kind" , p .kind )
281258 return len (keys ), nil
282259}
283260
@@ -302,7 +279,6 @@ func (p *persister[K, V]) Flush(ctx context.Context) (int, error) {
302279 return 0 , fmt .Errorf ("delete all entries: %w" , err )
303280 }
304281
305- slog .Info ("flushed datastore cache" , "count" , len (keys ), "kind" , p .kind )
306282 return len (keys ), nil
307283}
308284
0 commit comments