diff --git a/pkg/debrid/store/cache.go b/pkg/debrid/store/cache.go index 5c46750..7b6202e 100644 --- a/pkg/debrid/store/cache.go +++ b/pkg/debrid/store/cache.go @@ -89,7 +89,7 @@ type Cache struct { invalidDownloadLinks *xsync.Map[string, string] repairRequest *xsync.Map[string, *reInsertRequest] failedToReinsert *xsync.Map[string, struct{}] - failedLinksCounter *xsync.Map[string, *atomic.Int32] // link -> counter + failedLinksCounter *xsync.Map[string, atomic.Int32] // link -> counter // repair repairChan chan RepairRequest @@ -198,7 +198,7 @@ func NewDebridCache(dc config.Debrid, client common.Client, mounter *rclone.Moun invalidDownloadLinks: xsync.NewMap[string, string](), repairRequest: xsync.NewMap[string, *reInsertRequest](), failedToReinsert: xsync.NewMap[string, struct{}](), - failedLinksCounter: xsync.NewMap[string, *atomic.Int32](), + failedLinksCounter: xsync.NewMap[string, atomic.Int32](), streamClient: httpClient, repairChan: make(chan RepairRequest, 100), // Initialize the repair channel, max 100 requests buffered } diff --git a/pkg/debrid/store/download_link.go b/pkg/debrid/store/download_link.go index dcbdfce..f8320f7 100644 --- a/pkg/debrid/store/download_link.go +++ b/pkg/debrid/store/download_link.go @@ -146,12 +146,16 @@ func (c *Cache) checkDownloadLink(link string) (types.DownloadLink, error) { return types.DownloadLink{}, fmt.Errorf("download link not found for %s", link) } +func (c *Cache) IncrementFailedLinkCounter(link string) int32 { + counter, _ := c.failedLinksCounter.LoadOrCompute(link, func() (atomic.Int32, bool) { + return atomic.Int32{}, true + }) + return counter.Add(1) +} + func (c *Cache) MarkLinkAsInvalid(downloadLink types.DownloadLink, reason string) { // Increment file link error counter - counter, _ := c.failedLinksCounter.LoadOrCompute(downloadLink.Link, func() (*atomic.Int32, bool) { - return &atomic.Int32{}, true - }) - counter.Add(1) + c.IncrementFailedLinkCounter(downloadLink.Link) c.invalidDownloadLinks.Store(downloadLink.DownloadLink, reason) // Remove the download api key from active