From b61480b3091ed62b23e5a42be8a5cc7ad3679692 Mon Sep 17 00:00:00 2001 From: Goldy <153996346+g0ldyy@users.noreply.github.com> Date: Sun, 24 Nov 2024 17:21:43 +0100 Subject: [PATCH] fix: postgresql support --- comet/api/stream.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/comet/api/stream.py b/comet/api/stream.py index 8bbcb2d..eda303f 100644 --- a/comet/api/stream.py +++ b/comet/api/stream.py @@ -186,15 +186,15 @@ async def stream( for debrid_service in services: cached_results = await database.fetch_all( - """ - SELECT info_hash, tracker, data - FROM cache - WHERE debridService = :debrid_service - AND name = :name - AND ((:season IS NULL AND season IS NULL) OR season = :season) - AND ((:episode IS NULL AND episode IS NULL) OR episode = :episode) - AND tracker IN (SELECT value FROM json_each(:indexers)) - AND timestamp + :cache_ttl >= :current_time + f""" + SELECT info_hash, tracker, data + FROM cache + WHERE debridService = :debrid_service + AND name = :name + AND ((cast(:season as INTEGER) IS NULL AND season IS NULL) OR season = cast(:season as INTEGER)) + AND ((cast(:episode as INTEGER) IS NULL AND episode IS NULL) OR episode = cast(:episode as INTEGER)) + AND tracker IN (SELECT cast(value as TEXT) FROM {'json_array_elements_text' if settings.DATABASE_TYPE == 'postgresql' else 'json_each'}(:indexers)) + AND timestamp + :cache_ttl >= :current_time """, { "debrid_service": debrid_service, @@ -208,7 +208,12 @@ async def stream( ) for result in cached_results: trackers_found.add(result["tracker"].lower()) - all_sorted_ranked_files[result["info_hash"]] = orjson.loads( + + hash = result["info_hash"] + if "searched" in hash: + continue + + all_sorted_ranked_files[hash] = orjson.loads( result["data"] )