Refresh stale SAB category ignores

Drop old ignored SAB rows before resync so fixed category parsing can take effect.
This commit is contained in:
2026-07-29 15:08:32 +02:00
parent 2ff670a9ae
commit 581934f7b5
3 changed files with 22 additions and 0 deletions
+1
View File
@@ -275,6 +275,7 @@ async def sync_queue() -> None:
state.upsert_queue_item(source_type="system", source_id="sab-sync", name="SABnzbd", state="failed", reason=exc.__class__.__name__)
return
slots = data.get("history", {}).get("slots", [])
state.delete_queue_items_by_state("sab", "ignored", "SAB category is not owned by Importarr")
for item in slots:
readiness = classify_history_item(item, active, settings.sab_category, settings.download_root)
job_id = str(item.get("nzo_id") or item.get("nzoid") or item.get("name") or "")
+8
View File
@@ -146,6 +146,14 @@ class State:
self.conn.commit()
return cursor.rowcount > 0
def delete_queue_items_by_state(self, source_type: str, state: str, reason: str | None = None) -> int:
if reason is None:
cursor = self.conn.execute("delete from import_queue_items where source_type = ? and state = ?", (source_type, state))
else:
cursor = self.conn.execute("delete from import_queue_items where source_type = ? and state = ? and reason = ?", (source_type, state, reason))
self.conn.commit()
return cursor.rowcount
def get_queue_item(self, item_id: int) -> dict[str, Any] | None:
row = self.conn.execute("select * from import_queue_items where id = ?", (item_id,)).fetchone()
return dict(row) if row else None
+13
View File
@@ -0,0 +1,13 @@
from importarr.state import State
def test_delete_queue_items_by_state_can_target_reason(tmp_path):
state = State(tmp_path / "state.db")
state.upsert_queue_item(source_type="sab", source_id="stale", name="Stale", state="ignored", reason="SAB category is not owned by Importarr")
state.upsert_queue_item(source_type="sab", source_id="other", name="Other", state="ignored", reason="other reason")
assert state.delete_queue_items_by_state("sab", "ignored", "SAB category is not owned by Importarr") == 1
rows = state.list_queue_items()
assert len(rows) == 1
assert rows[0]["source_id"] == "other"