diff options
author | Profpatsch <mail@profpatsch.de> | 2024-05-11T20·35+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-05-13T14·50+0000 |
commit | a2d56cedaf4ef7c5a52e4029581eb692814441fa (patch) | |
tree | cf3e54c8b50570e86e091cca0c0892579d00d1f7 | |
parent | f79c1869093b779a4498b3dc832da0304ff14d90 (diff) |
feat(users/Profpatsch/whatcd-resolver): allow listing only download r/8131
When showing the best torrents table, we want to be able to filter for “only downloaded”. Change-Id: Ibfe9212f3d422d305f858fbef023ee985c1183d6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11650 Autosubmit: Profpatsch <mail@profpatsch.de> Reviewed-by: Profpatsch <mail@profpatsch.de> Tested-by: BuildkiteCI
-rw-r--r-- | users/Profpatsch/whatcd-resolver/src/Redacted.hs | 11 | ||||
-rw-r--r-- | users/Profpatsch/whatcd-resolver/src/WhatcdResolver.hs | 4 |
2 files changed, 9 insertions, 6 deletions
diff --git a/users/Profpatsch/whatcd-resolver/src/Redacted.hs b/users/Profpatsch/whatcd-resolver/src/Redacted.hs index 4369c184087a..c0c26b72d659 100644 --- a/users/Profpatsch/whatcd-resolver/src/Redacted.hs +++ b/users/Profpatsch/whatcd-resolver/src/Redacted.hs @@ -382,8 +382,8 @@ getTorrentById dat = do >>= ensureSingleRow -- | Find the best torrent for each torrent group (based on the seeding_weight) -getBestTorrents :: (MonadPostgres m) => Transaction m [TorrentData ()] -getBestTorrents = do +getBestTorrents :: (MonadPostgres m, HasField "onlyDownloaded" opts Bool) => opts -> Transaction m [TorrentData ()] +getBestTorrents opts = do queryWith [sql| SELECT * FROM ( @@ -393,15 +393,18 @@ getBestTorrents = do seeding_weight, t.full_json_result AS torrent_json, tg.full_json_result AS torrent_group_json, - t.torrent_file IS NOT NULL, + t.torrent_file IS NOT NULL as has_torrent_file, t.transmission_torrent_hash FROM redacted.torrents t JOIN redacted.torrent_groups tg ON tg.id = t.torrent_group ORDER BY group_id, seeding_weight DESC ) as _ + WHERE + -- onlyDownloaded + ((NOT ?::bool) OR has_torrent_file) ORDER BY seeding_weight DESC |] - () + (Only opts.onlyDownloaded :: Only Bool) ( do groupId <- Dec.fromField @Int torrentId <- Dec.fromField @Int diff --git a/users/Profpatsch/whatcd-resolver/src/WhatcdResolver.hs b/users/Profpatsch/whatcd-resolver/src/WhatcdResolver.hs index 26213c5fea32..d8e7889d3e98 100644 --- a/users/Profpatsch/whatcd-resolver/src/WhatcdResolver.hs +++ b/users/Profpatsch/whatcd-resolver/src/WhatcdResolver.hs @@ -306,7 +306,7 @@ htmlUi = do |] artistPage :: (HasField "dbId" dat Text, Applicative m) => dat -> m Html -artistPage dat = +artistPage dat = do pure [hsx| Artist ID: {dat.dbId} @@ -438,7 +438,7 @@ getBestTorrentsTable :: ) => Transaction m Html getBestTorrentsTable = do - bestStale :: [TorrentData ()] <- getBestTorrents + bestStale :: [TorrentData ()] <- getBestTorrents (label @"onlyDownloaded" False) actual <- getAndUpdateTransmissionTorrentsStatus ( bestStale |