feat(users/Profpatsch/whatcd-resolver): add release type filter

For latest releases, I really don’t want to see bootlegs and stuff.

Change-Id: I3a98d7b81d2ca7962dcef619d4dcfcbd18e98f84
Reviewed-on: https://cl.tvl.fyi/c/depot/+/13226
Reviewed-by: Profpatsch <mail@profpatsch.de>
Tested-by: BuildkiteCI
This commit is contained in:
Profpatsch 2025-03-09 15:56:12 +01:00
parent fc7f013066
commit 2adf7b5634
2 changed files with 25 additions and 7 deletions

View file

@ -622,6 +622,7 @@ getTorrentById dat = do
data GetBestTorrentsFilter = GetBestTorrentsFilter data GetBestTorrentsFilter = GetBestTorrentsFilter
{ onlyArtist :: Maybe (Label "artistRedactedId" Int), { onlyArtist :: Maybe (Label "artistRedactedId" Int),
onlyTheseTorrents :: Maybe ([Label "torrentId" Int]), onlyTheseTorrents :: Maybe ([Label "torrentId" Int]),
disallowedReleaseTypes :: [ReleaseType],
limitResults :: Maybe Natural, limitResults :: Maybe Natural,
ordering :: BestTorrentsOrdering ordering :: BestTorrentsOrdering
} }
@ -672,6 +673,7 @@ getBestTorrents opts = do
FROM filtered_torrents f FROM filtered_torrents f
JOIN redacted.torrents t ON t.id = f.id JOIN redacted.torrents t ON t.id = f.id
JOIN redacted.torrent_groups tg ON tg.id = t.torrent_group JOIN redacted.torrent_groups tg ON tg.id = t.torrent_group
WHERE tg.full_json_result->>'releaseType' <> ALL (?::text[])
|] |]
<> case opts.ordering of <> case opts.ordering of
BySeedingWeight -> [fmt|ORDER BY seeding_weight DESC|] <> "\n" BySeedingWeight -> [fmt|ORDER BY seeding_weight DESC|] <> "\n"
@ -691,6 +693,7 @@ getBestTorrents opts = do
onlyArtistId :: Int, onlyArtistId :: Int,
onlyTheseTorrentsB :: Bool, onlyTheseTorrentsB :: Bool,
onlyTheseTorrents, onlyTheseTorrents,
(opts.disallowedReleaseTypes & concatMap (\rt -> [rt.stringKey, rt.intKey & buildText intDecimalT]) & PGArray :: PGArray Text),
opts.limitResults <&> naturalToInteger :: Maybe Integer opts.limitResults <&> naturalToInteger :: Maybe Integer
) )
) )

View file

@ -159,7 +159,7 @@ htmlUi = do
( do ( do
d <- d <-
getBestTorrentsData getBestTorrentsData
(t2 #limitResults Nothing #ordering BySeedingWeight) (t3 #limitResults Nothing #ordering BySeedingWeight #disallowedReleaseTypes [])
( Just ( Just
( E21 ( E21
(label @"onlyTheseTorrents" res.newTorrents) (label @"onlyTheseTorrents" res.newTorrents)
@ -380,9 +380,22 @@ htmlUi = do
(bestTorrentsTable, settings) <- (bestTorrentsTable, settings) <-
concurrentlyTraced concurrentlyTraced
( do ( do
d <- getBestTorrentsData (t2 #limitResults (Just 30) #ordering ByLastReleases) Nothing d <-
getBestTorrentsData
( t3
#limitResults
(Just 100)
#ordering
ByLastReleases
#disallowedReleaseTypes
[ releaseTypeBootleg,
releaseTypeGuestAppearance,
releaseTypeRemix
]
)
Nothing
pure $ case d & nonEmpty of pure $ case d & nonEmpty of
Nothing -> [hsx|<h1>Last Releases</h1><p>No torrents found</p>|] Nothing -> [hsx|<h1>Latest Releases</h1><p>No torrents found</p>|]
Just d' -> mkBestTorrentsTableSection (lbl #sectionName "Last Releases") d' Just d' -> mkBestTorrentsTableSection (lbl #sectionName "Last Releases") d'
) )
(getSettings) (getSettings)
@ -588,7 +601,7 @@ artistPage dat = runTransaction $ do
(fresh, settings) <- (fresh, settings) <-
concurrentlyTraced concurrentlyTraced
( getBestTorrentsData ( getBestTorrentsData
(t2 #limitResults Nothing #ordering BySeedingWeight) (t3 #limitResults Nothing #ordering BySeedingWeight #disallowedReleaseTypes [])
(Just $ E22 (getLabel @"artistRedactedId" dat)) (Just $ E22 (getLabel @"artistRedactedId" dat))
) )
(getSettings) (getSettings)
@ -827,7 +840,8 @@ getBestTorrentsData ::
MonadPostgres m, MonadPostgres m,
MonadOtel m, MonadOtel m,
HasField "limitResults" opts (Maybe Natural), HasField "limitResults" opts (Maybe Natural),
HasField "ordering" opts BestTorrentsOrdering HasField "ordering" opts BestTorrentsOrdering,
HasField "disallowedReleaseTypes" opts [ReleaseType]
) => ) =>
opts -> opts ->
Maybe (E2 "onlyTheseTorrents" [Label "torrentId" Int] "artistRedactedId" Int) -> Maybe (E2 "onlyTheseTorrents" [Label "torrentId" Int] "artistRedactedId" Int) ->
@ -840,6 +854,7 @@ getBestTorrentsData opts filters = inSpan' "get torrents table data" $ \span ->
let limitResults = getField @"limitResults" opts let limitResults = getField @"limitResults" opts
let ordering = opts.ordering let ordering = opts.ordering
let disallowedReleaseTypes = opts.disallowedReleaseTypes
let getBest = getBestTorrents GetBestTorrentsFilter {..} let getBest = getBestTorrents GetBestTorrentsFilter {..}
bestStale :: [TorrentData ()] <- getBest bestStale :: [TorrentData ()] <- getBest
(statusInfo, transmissionStatus) <- (statusInfo, transmissionStatus) <-
@ -935,7 +950,7 @@ mkBestTorrentsTableSection opts torrents = do
(label @"content" $ Html.toHtml @Text a.artistName) (label @"content" $ Html.toHtml @Text a.artistName)
) )
& mkLinkList & mkLinkList
let releaseTypeTooltip rt = [fmt|{rt.stringKey} (Release type ID: {rt.intKey})|] :: Text
[hsx| [hsx|
<tr id={torrentPosition}> <tr id={torrentPosition}>
<td>{localTorrent b}</td> <td>{localTorrent b}</td>
@ -948,7 +963,7 @@ mkBestTorrentsTableSection opts torrents = do
{Html.toHtml @Text b.torrentGroupJson.groupName} {Html.toHtml @Text b.torrentGroupJson.groupName}
</a> </a>
</td> </td>
<td>{Html.toHtml @Text b.releaseType.stringKey}</td> <td title={releaseTypeTooltip b.releaseType}>{Html.toHtml @Text b.releaseType.stringKey}</td>
<td>{Html.toHtml @Natural b.torrentGroupJson.groupYear}</td> <td>{Html.toHtml @Natural b.torrentGroupJson.groupYear}</td>
<td>{Html.toHtml @Int b.seedingWeight}</td> <td>{Html.toHtml @Int b.seedingWeight}</td>
<td>{Html.toHtml @Text b.torrentFormat}</td> <td>{Html.toHtml @Text b.torrentFormat}</td>