Skip to content

Commit

Permalink
fix: fixed completed items being added to queue on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
dreulavelle committed Sep 2, 2024
1 parent 44e0161 commit d45882f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/program/db/db_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ def _store_item(item: "MediaItem"):
with db.Session() as session:
_check_for_and_run_insertion_required(session, item)

def _imdb_exists_in_db(imdb_id: str) -> bool:
from program.media.item import MediaItem
with db.Session() as session:
return session.execute(select(func.count(MediaItem._id)).where(MediaItem.imdb_id == imdb_id)).scalar_one() != 0

def _get_item_from_db(session, item: "MediaItem"):
from program.media.item import MediaItem, Movie, Show, Season, Episode
if not _ensure_item_exists_in_db(item):
Expand Down
4 changes: 4 additions & 0 deletions src/program/state_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from program.symlink import Symlinker
from program.types import ProcessedEvent, Service
from program.updaters import Updater
from program.db.db_functions import _imdb_exists_in_db
from utils.logger import logger
from program.settings.manager import settings_manager

Expand All @@ -24,6 +25,9 @@ def process_event(existing_item: MediaItem | None, emitted_by: Service, item: Me
source_services = (Overseerr, PlexWatchlist, Listrr, Mdblist, SymlinkLibrary, TraktContent)
if emitted_by in source_services or item.state in [States.Requested]:
next_service = TraktIndexer
if _imdb_exists_in_db(item.imdb_id):
logger.debug(f"Item {item.log_string} already exists in the database.")
return no_further_processing
if isinstance(item, Season):
item = item.parent
existing_item = existing_item.parent if existing_item else None
Expand Down

0 comments on commit d45882f

Please sign in to comment.