Skip to content

fix-tags-cache - #314

Open
spyhunter493 wants to merge 4 commits into
jon4hz:mainfrom
spyhunter493:fix-tags-bug
Open

fix-tags-cache#314
spyhunter493 wants to merge 4 commits into
jon4hz:mainfrom
spyhunter493:fix-tags-bug

Conversation

@spyhunter493

Copy link
Copy Markdown

Fixes #222

Problem

Once a media item was marked for deletion and stored in the database, adding an exclude tag to it in Sonarr or Radarr had no effect. The database filter runs first in the pipeline and excludes already-queued items from all subsequent filters, meaning the tags filter never had a chance to re-evaluate them. The only workaround was deleting the entire database.

Additionally, getTags() in both the Sonarr and Radarr clients contained dead code: forceRefresh=true was always passed from GetItems(), which cleared the cache immediately before checking it — making the cache check condition (len(cachedTags) != 0 && !forceRefresh) impossible to satisfy. This caused a misleading "Failed to get Sonarr/Radarr tags from cache" debug log on every single run.

Changes
• Added removeItemsWithExcludedTags() to the engine, called each cleanup cycle after gatherMediaItems. It cross-references items currently in the database against their freshly-fetched tag state from Sonarr/Radarr. Any item that now carries an exclude tag (or jellysweep-ignore) is removed from the deletion queue automatically.
• Added DBDeleteReasonExcludeTag so history events correctly reflect why an item was removed from the queue.
• Simplified getTags() in both Sonarr and Radarr clients to fix the inverted cache logic — cache is now read when forceRefresh=false and bypassed when forceRefresh=true, as intended. Eliminates the spurious cache-miss debug log.

spyhunter493 and others added 2 commits March 31, 2026 07:53
Resolves the issue were tags are not updated from radarr/sonarr after initial DB startup

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes #222 by restoring effectiveness of Sonarr/Radarr exclude tags after items have already been queued for deletion, and corrects an inverted cache check in the tags cache that caused every run to bypass the cache and emit a misleading log.

Changes:

  • Adds removeItemsWithExcludedTags in the engine to cross-reference already-queued items against fresh Arr tag state and remove them from the queue when an exclude tag (or jellysweep-ignore) is now present.
  • Introduces DBDeleteReasonExcludeTag to label such removals.
  • Rewrites getTags in both the Sonarr and Radarr clients so the cache is consulted only when forceRefresh=false, eliminating the always-failing cache check and its spurious debug log.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
internal/engine/engine.go Adds removeItemsWithExcludedTags and invokes it after gathering media items in the cleanup job.
internal/engine/arr/sonarr/sonarr.go Simplifies getTags so caching is actually used when forceRefresh is false.
internal/engine/arr/radarr/radarr.go Same caching fix as Sonarr for the Radarr client.
internal/database/interface.go Adds new DBDeleteReasonExcludeTag constant for the new removal path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/engine/engine.go
Comment on lines +409 to +416
if shouldRemove {
log.Info("Removing item from deletion queue due to exclude tag", "title", dbItem.Title, "tag", tagName)
dbItem.DBDeleteReason = database.DBDeleteReasonExcludeTag
if err := e.db.DeleteMediaItem(ctx, &dbItem); err != nil {
log.Error("Failed to remove item from database", "title", dbItem.Title, "error", err)
}
break
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clanker is right. There should be an event for the history db that an item is now ignored.

Please see https://github.com/jon4hz/jellysweep/blob/main/internal/engine/events.go as a starting point.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added f2d79c1 something like this?

Comment thread internal/engine/engine.go
Comment thread internal/engine/arr/sonarr/sonarr.go
Comment thread internal/engine/arr/radarr/radarr.go
Comment thread internal/engine/engine.go
@jon4hz

jon4hz commented Aug 3, 2026

Copy link
Copy Markdown
Owner

@spyhunter493 can you take a look at the review comments? Especially #314 (comment) should be addressed.

If you don't have the time, please let me know, and I'll do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Sonarr/Radar Exclude Tags

3 participants