From 654b2618aef2ed4c7f4ef69a355cb0fcfe1792ec Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Wed, 10 Apr 2024 14:46:05 +0300 Subject: [PATCH] add sync.RWMutex to listCache --- server/settings/dbreadcache.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/settings/dbreadcache.go b/server/settings/dbreadcache.go index 73e66f4..897314a 100644 --- a/server/settings/dbreadcache.go +++ b/server/settings/dbreadcache.go @@ -8,6 +8,7 @@ import ( type DBReadCache struct { db TorrServerDB listCache map[string][]string + listCacheMutex sync.RWMutex dataCache map[[2]string][]byte dataCacheMutex sync.RWMutex } @@ -57,11 +58,16 @@ func (v *DBReadCache) Set(xPath, name string, value []byte) { } func (v *DBReadCache) List(xPath string) []string { + v.listCacheMutex.RLock() if names, ok := v.listCache[xPath]; ok { + defer v.listCacheMutex.RUnlock() return names } + v.listCacheMutex.RUnlock() names := v.db.List(xPath) + v.listCacheMutex.Lock() v.listCache[xPath] = names + v.listCacheMutex.Unlock() return names }