refactor(users/Profpatsch/whatcd-resolver): prepare SQL changes

For the next step, we need to put more things in WITH-Clauses, so
let’s prepare it now to get a nicer diff.

Change-Id: Ibd5b67c77c87ce3d6aa0ab04ca3d66f9b90dc856
Reviewed-on: https://cl.tvl.fyi/c/depot/+/13237
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
This commit is contained in:
Profpatsch 2025-03-10 12:51:01 +01:00
parent 2adf7b5634
commit 1e188ee116

View file

@ -653,7 +653,8 @@ getBestTorrents opts = do
-- prefer torrents which we already downloaded
torrent_file,
seeding_weight DESC
)
),
prepare1 AS (
SELECT
tg.group_id,
t.torrent_id,
@ -673,11 +674,25 @@ getBestTorrents opts = do
FROM filtered_torrents f
JOIN redacted.torrents t ON t.id = f.id
JOIN redacted.torrent_groups tg ON tg.id = t.torrent_group
WHERE tg.full_json_result->>'releaseType' <> ALL (?::text[])
WHERE
tg.full_json_result->>'releaseType' <> ALL (?::text[])
)
SELECT
group_id,
torrent_id,
seeding_weight,
release_type,
artists,
group_name,
group_year,
has_torrent_file,
transmission_torrent_hash,
torrent_format
FROM prepare1
|]
<> case opts.ordering of
BySeedingWeight -> [fmt|ORDER BY seeding_weight DESC|] <> "\n"
ByLastReleases -> [fmt|ORDER BY tg.group_id DESC|] <> "\n"
ByLastReleases -> [fmt|ORDER BY group_id DESC|] <> "\n"
<> [sql|
LIMIT ?::int
|]