Move fully off zsync. Defaults ot simple maps with mutexes
This commit is contained in:
1
go.mod
1
go.mod
@@ -12,7 +12,6 @@ require (
|
|||||||
github.com/goccy/go-json v0.10.5
|
github.com/goccy/go-json v0.10.5
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/gorilla/sessions v1.4.0
|
github.com/gorilla/sessions v1.4.0
|
||||||
github.com/puzpuzpuz/xsync/v4 v4.1.0
|
|
||||||
github.com/robfig/cron/v3 v3.0.1
|
github.com/robfig/cron/v3 v3.0.1
|
||||||
github.com/rs/zerolog v1.33.0
|
github.com/rs/zerolog v1.33.0
|
||||||
github.com/stanNthe5/stringbuf v0.0.3
|
github.com/stanNthe5/stringbuf v0.0.3
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -185,8 +185,6 @@ github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R
|
|||||||
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||||
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
|
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
|
||||||
github.com/prometheus/procfs v0.0.11/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
|
github.com/prometheus/procfs v0.0.11/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
|
||||||
github.com/puzpuzpuz/xsync/v4 v4.1.0 h1:x9eHRl4QhZFIPJ17yl4KKW9xLyVWbb3/Yq4SXpjF71U=
|
|
||||||
github.com/puzpuzpuz/xsync/v4 v4.1.0/go.mod h1:VJDmTCJMBt8igNxnkQd86r+8KUeN1quSfNKu5bLYFQo=
|
|
||||||
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ func (a *Arr) Validate() error {
|
|||||||
|
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
Arrs map[string]*Arr // name -> arr
|
Arrs map[string]*Arr // name -> arr
|
||||||
mu sync.RWMutex
|
mu sync.Mutex
|
||||||
logger zerolog.Logger
|
logger zerolog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,14 +159,14 @@ func (as *Storage) AddOrUpdate(arr *Arr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (as *Storage) Get(name string) *Arr {
|
func (as *Storage) Get(name string) *Arr {
|
||||||
as.mu.RLock()
|
as.mu.Lock()
|
||||||
defer as.mu.RUnlock()
|
defer as.mu.Unlock()
|
||||||
return as.Arrs[name]
|
return as.Arrs[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (as *Storage) GetAll() []*Arr {
|
func (as *Storage) GetAll() []*Arr {
|
||||||
as.mu.RLock()
|
as.mu.Lock()
|
||||||
defer as.mu.RUnlock()
|
defer as.mu.Unlock()
|
||||||
arrs := make([]*Arr, 0, len(as.Arrs))
|
arrs := make([]*Arr, 0, len(as.Arrs))
|
||||||
for _, arr := range as.Arrs {
|
for _, arr := range as.Arrs {
|
||||||
if arr.Host != "" && arr.Token != "" {
|
if arr.Host != "" && arr.Token != "" {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/puzpuzpuz/xsync/v4"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -73,7 +72,7 @@ type Cache struct {
|
|||||||
logger zerolog.Logger
|
logger zerolog.Logger
|
||||||
|
|
||||||
torrents *torrentCache
|
torrents *torrentCache
|
||||||
downloadLinks *xsync.Map[string, linkCache]
|
downloadLinks *downloadLinkCache
|
||||||
invalidDownloadLinks sync.Map
|
invalidDownloadLinks sync.Map
|
||||||
folderNaming WebDavFolderNaming
|
folderNaming WebDavFolderNaming
|
||||||
|
|
||||||
@@ -139,7 +138,7 @@ func New(dc config.Debrid, client types.Client) *Cache {
|
|||||||
client: client,
|
client: client,
|
||||||
logger: logger.New(fmt.Sprintf("%s-webdav", client.GetName())),
|
logger: logger.New(fmt.Sprintf("%s-webdav", client.GetName())),
|
||||||
workers: dc.Workers,
|
workers: dc.Workers,
|
||||||
downloadLinks: xsync.NewMap[string, linkCache](),
|
downloadLinks: newDownloadLinkCache(),
|
||||||
torrentRefreshInterval: dc.TorrentsRefreshInterval,
|
torrentRefreshInterval: dc.TorrentsRefreshInterval,
|
||||||
downloadLinksRefreshInterval: dc.DownloadLinksRefreshInterval,
|
downloadLinksRefreshInterval: dc.DownloadLinksRefreshInterval,
|
||||||
folderNaming: WebDavFolderNaming(dc.FolderNaming),
|
folderNaming: WebDavFolderNaming(dc.FolderNaming),
|
||||||
@@ -151,7 +150,7 @@ func New(dc config.Debrid, client types.Client) *Cache {
|
|||||||
config: dc,
|
config: dc,
|
||||||
customFolders: customFolders,
|
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)
|
c.RefreshListings(refreshRclone)
|
||||||
})
|
})
|
||||||
return c
|
return c
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/sirrobot01/decypharr/internal/request"
|
"github.com/sirrobot01/decypharr/internal/request"
|
||||||
"github.com/sirrobot01/decypharr/pkg/debrid/types"
|
"github.com/sirrobot01/decypharr/pkg/debrid/types"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,6 +16,33 @@ type linkCache struct {
|
|||||||
expiresAt time.Time
|
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 {
|
type downloadLinkRequest struct {
|
||||||
result string
|
result string
|
||||||
err error
|
err error
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ func (c *Cache) reInsertTorrent(ct *CachedTorrent) (*CachedTorrent, error) {
|
|||||||
IsComplete: len(newTorrent.Files) > 0,
|
IsComplete: len(newTorrent.Files) > 0,
|
||||||
}
|
}
|
||||||
c.setTorrent(newCt, func(torrent CachedTorrent) {
|
c.setTorrent(newCt, func(torrent CachedTorrent) {
|
||||||
c.listingDebouncer.Call(true)
|
c.RefreshListings(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
ct = &newCt // Update ct to point to the new torrent
|
ct = &newCt // Update ct to point to the new torrent
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ type directoryFilter struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type torrentCache struct {
|
type torrentCache struct {
|
||||||
mu sync.RWMutex
|
mu sync.Mutex
|
||||||
byID map[string]CachedTorrent
|
byID map[string]CachedTorrent
|
||||||
byName map[string]CachedTorrent
|
byName map[string]CachedTorrent
|
||||||
listing atomic.Value
|
listing atomic.Value
|
||||||
@@ -74,15 +74,15 @@ func newTorrentCache(dirFilters map[string][]directoryFilter) *torrentCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tc *torrentCache) getByID(id string) (CachedTorrent, bool) {
|
func (tc *torrentCache) getByID(id string) (CachedTorrent, bool) {
|
||||||
tc.mu.RLock()
|
tc.mu.Lock()
|
||||||
defer tc.mu.RUnlock()
|
defer tc.mu.Unlock()
|
||||||
torrent, exists := tc.byID[id]
|
torrent, exists := tc.byID[id]
|
||||||
return torrent, exists
|
return torrent, exists
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tc *torrentCache) getByName(name string) (CachedTorrent, bool) {
|
func (tc *torrentCache) getByName(name string) (CachedTorrent, bool) {
|
||||||
tc.mu.RLock()
|
tc.mu.Lock()
|
||||||
defer tc.mu.RUnlock()
|
defer tc.mu.Unlock()
|
||||||
torrent, exists := tc.byName[name]
|
torrent, exists := tc.byName[name]
|
||||||
return torrent, exists
|
return torrent, exists
|
||||||
}
|
}
|
||||||
@@ -256,8 +256,8 @@ func (tc *torrentCache) torrentMatchDirectory(filters []directoryFilter, file so
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tc *torrentCache) getAll() map[string]CachedTorrent {
|
func (tc *torrentCache) getAll() map[string]CachedTorrent {
|
||||||
tc.mu.RLock()
|
tc.mu.Lock()
|
||||||
defer tc.mu.RUnlock()
|
defer tc.mu.Unlock()
|
||||||
result := make(map[string]CachedTorrent)
|
result := make(map[string]CachedTorrent)
|
||||||
for name, torrent := range tc.byName {
|
for name, torrent := range tc.byName {
|
||||||
result[name] = torrent
|
result[name] = torrent
|
||||||
@@ -266,8 +266,8 @@ func (tc *torrentCache) getAll() map[string]CachedTorrent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tc *torrentCache) getAllIDs() []string {
|
func (tc *torrentCache) getAllIDs() []string {
|
||||||
tc.mu.RLock()
|
tc.mu.Lock()
|
||||||
defer tc.mu.RUnlock()
|
defer tc.mu.Unlock()
|
||||||
ids := make([]string, 0, len(tc.byID))
|
ids := make([]string, 0, len(tc.byID))
|
||||||
for id := range tc.byID {
|
for id := range tc.byID {
|
||||||
ids = append(ids, id)
|
ids = append(ids, id)
|
||||||
@@ -276,8 +276,8 @@ func (tc *torrentCache) getAllIDs() []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tc *torrentCache) getIdMaps() map[string]struct{} {
|
func (tc *torrentCache) getIdMaps() map[string]struct{} {
|
||||||
tc.mu.RLock()
|
tc.mu.Lock()
|
||||||
defer tc.mu.RUnlock()
|
defer tc.mu.Unlock()
|
||||||
res := make(map[string]struct{}, len(tc.byID))
|
res := make(map[string]struct{}, len(tc.byID))
|
||||||
for id, _ := range tc.byID {
|
for id, _ := range tc.byID {
|
||||||
res[id] = struct{}{}
|
res[id] = struct{}{}
|
||||||
|
|||||||
Reference in New Issue
Block a user