Skip to content

Commit

Permalink
fix: postgresql support
Browse files Browse the repository at this point in the history
  • Loading branch information
g0ldyy committed Nov 24, 2024
1 parent 8122689 commit b61480b
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions comet/api/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"]
)

Expand Down

0 comments on commit b61480b

Please sign in to comment.