Move fully off zsync. Defaults ot simple maps with mutexes

This commit is contained in:
Mukhtar Akere
2025-05-14 14:55:18 +01:00
parent 64edc5547d
commit 3c8e6bae81
7 changed files with 48 additions and 24 deletions
+3 -4
View File
@@ -6,7 +6,6 @@ import (
"context"
"errors"
"fmt"
"github.com/puzpuzpuz/xsync/v4"
"os"
"path"
"path/filepath"
@@ -73,7 +72,7 @@ type Cache struct {
logger zerolog.Logger
torrents *torrentCache
downloadLinks *xsync.Map[string, linkCache]
downloadLinks *downloadLinkCache
invalidDownloadLinks sync.Map
folderNaming WebDavFolderNaming
@@ -139,7 +138,7 @@ func New(dc config.Debrid, client types.Client) *Cache {
client: client,
logger: logger.New(fmt.Sprintf("%s-webdav", client.GetName())),
workers: dc.Workers,
downloadLinks: xsync.NewMap[string, linkCache](),
downloadLinks: newDownloadLinkCache(),
torrentRefreshInterval: dc.TorrentsRefreshInterval,
downloadLinksRefreshInterval: dc.DownloadLinksRefreshInterval,
folderNaming: WebDavFolderNaming(dc.FolderNaming),
@@ -151,7 +150,7 @@ func New(dc config.Debrid, client types.Client) *Cache {
config: dc,
customFolders: customFolders,
}
c.listingDebouncer = utils.NewDebouncer[bool](250*time.Millisecond, func(refreshRclone bool) {
c.listingDebouncer = utils.NewDebouncer[bool](100*time.Millisecond, func(refreshRclone bool) {
c.RefreshListings(refreshRclone)
})
return c
+28
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/sirrobot01/decypharr/internal/request"
"github.com/sirrobot01/decypharr/pkg/debrid/types"
"sync"
"time"
)
@@ -15,6 +16,33 @@ type linkCache struct {
expiresAt time.Time
}
type downloadLinkCache struct {
data map[string]linkCache
mu sync.Mutex
}
func newDownloadLinkCache() *downloadLinkCache {
return &downloadLinkCache{
data: make(map[string]linkCache),
}
}
func (c *downloadLinkCache) Load(key string) (linkCache, bool) {
c.mu.Lock()
defer c.mu.Unlock()
dl, ok := c.data[key]
return dl, ok
}
func (c *downloadLinkCache) Store(key string, value linkCache) {
c.mu.Lock()
defer c.mu.Unlock()
c.data[key] = value
}
func (c *downloadLinkCache) Delete(key string) {
c.mu.Lock()
defer c.mu.Unlock()
delete(c.data, key)
}
type downloadLinkRequest struct {
result string
err error
+1 -1
View File
@@ -223,7 +223,7 @@ func (c *Cache) reInsertTorrent(ct *CachedTorrent) (*CachedTorrent, error) {
IsComplete: len(newTorrent.Files) > 0,
}
c.setTorrent(newCt, func(torrent CachedTorrent) {
c.listingDebouncer.Call(true)
c.RefreshListings(true)
})
ct = &newCt // Update ct to point to the new torrent
+11 -11
View File
@@ -41,7 +41,7 @@ type directoryFilter struct {
}
type torrentCache struct {
mu sync.RWMutex
mu sync.Mutex
byID map[string]CachedTorrent
byName map[string]CachedTorrent
listing atomic.Value
@@ -74,15 +74,15 @@ func newTorrentCache(dirFilters map[string][]directoryFilter) *torrentCache {
}
func (tc *torrentCache) getByID(id string) (CachedTorrent, bool) {
tc.mu.RLock()
defer tc.mu.RUnlock()
tc.mu.Lock()
defer tc.mu.Unlock()
torrent, exists := tc.byID[id]
return torrent, exists
}
func (tc *torrentCache) getByName(name string) (CachedTorrent, bool) {
tc.mu.RLock()
defer tc.mu.RUnlock()
tc.mu.Lock()
defer tc.mu.Unlock()
torrent, exists := tc.byName[name]
return torrent, exists
}
@@ -256,8 +256,8 @@ func (tc *torrentCache) torrentMatchDirectory(filters []directoryFilter, file so
}
func (tc *torrentCache) getAll() map[string]CachedTorrent {
tc.mu.RLock()
defer tc.mu.RUnlock()
tc.mu.Lock()
defer tc.mu.Unlock()
result := make(map[string]CachedTorrent)
for name, torrent := range tc.byName {
result[name] = torrent
@@ -266,8 +266,8 @@ func (tc *torrentCache) getAll() map[string]CachedTorrent {
}
func (tc *torrentCache) getAllIDs() []string {
tc.mu.RLock()
defer tc.mu.RUnlock()
tc.mu.Lock()
defer tc.mu.Unlock()
ids := make([]string, 0, len(tc.byID))
for id := range tc.byID {
ids = append(ids, id)
@@ -276,8 +276,8 @@ func (tc *torrentCache) getAllIDs() []string {
}
func (tc *torrentCache) getIdMaps() map[string]struct{} {
tc.mu.RLock()
defer tc.mu.RUnlock()
tc.mu.Lock()
defer tc.mu.Unlock()
res := make(map[string]struct{}, len(tc.byID))
for id, _ := range tc.byID {
res[id] = struct{}{}