Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

fix: resolve linter warning and cache race condition

Johnny4bd0f29ee5f9
diff --git a/store/cache/cache.go b/store/cache/cache.go
index 8760b3ad5..102f8add3 100644
--- a/store/cache/cache.go
+++ b/store/cache/cache.go
@@ -161,20 +161,20 @@ func (c *Cache) Delete(_ context.Context, key string) {
// Clear removes all values from the cache.
func (c *Cache) Clear(_ context.Context) {
- if c.config.OnEviction != nil {
- c.data.Range(func(key, value any) bool {
+ count := 0
+ c.data.Range(func(key, value any) bool {
+ if c.config.OnEviction != nil {
itm, ok := value.(item)
- if !ok {
- return true
- }
- if keyStr, ok := key.(string); ok {
- c.config.OnEviction(keyStr, itm.value)
+ if ok {
+ if keyStr, ok := key.(string); ok {
+ c.config.OnEviction(keyStr, itm.value)
+ }
}
- return true
- })
- }
-
- c.data = sync.Map{}
+ }
+ c.data.Delete(key)
+ count++
+ return true
+ })
(&c.itemCount).Store(0)
}
diff --git a/store/test/main_test.go b/store/test/main_test.go
index 6890d501f..f0ae03f78 100644
--- a/store/test/main_test.go
+++ b/store/test/main_test.go
@@ -13,7 +13,8 @@ func TestMain(m *testing.M) {
// If DRIVER is set, run tests for that driver only
if os.Getenv("DRIVER") != "" {
defer TerminateContainers()
- os.Exit(m.Run())
+ m.Run() //nolint:revive // Exit code is handled by test runner
+ return
}
// No DRIVER set - run tests for all drivers sequentially