fix: postgresql support

This commit is contained in:
Goldy
2024-11-24 17:21:43 +01:00
parent 812268971d
commit b61480b309
+15 -10
View File
@@ -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"]
)