feat(users/Profpatsch/whatcd-resolver): add simple settings

For now just a setting whether we want to use freeleech tokens.

Change-Id: I1c0228031df8c79c2ec26ec5bdfef6dde1cb373e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/13007
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
This commit is contained in:
Profpatsch 2025-01-16 20:18:34 +01:00
parent 3e5b3b82a6
commit 3953fd7030
6 changed files with 286 additions and 58 deletions

View file

@ -80,6 +80,9 @@ module MyPrelude
MonadTrans,
lift,
-- * Kinds
Type,
-- * Data types
Coercible,
coerce,
@ -154,6 +157,7 @@ module MyPrelude
Category,
(>>>),
(&>>),
cconst,
Any,
-- * Enum definition
@ -174,6 +178,7 @@ where
import Control.Applicative ((<|>))
import Control.Category (Category, (>>>))
import Control.Category qualified as Category
import Control.Foldl.NonEmpty qualified as Foldl1
import Control.Monad (guard, join, unless, when)
import Control.Monad.Catch (MonadThrow (throwM))
@ -200,6 +205,7 @@ import Data.Function ((&))
import Data.Functor ((<&>))
import Data.Functor.Contravariant (Contravariant (contramap), (>$<))
import Data.Functor.Identity (Identity (runIdentity))
import Data.Kind (Type)
import Data.List (zip4)
import Data.List qualified as List
import Data.List.NonEmpty (NonEmpty ((:|)), nonEmpty)
@ -286,6 +292,11 @@ infixl 5 >&<
-- like >>>
infixr 1 &>>
-- | Categorical constant function,
-- like 'const' but works for anything thats a category and profunctor.
cconst :: (Category c, Profunctor c) => b -> c a b
cconst b = Category.id & rmap (\_ -> b)
-- | encode a Text to a UTF-8 encoded Bytestring
textToBytesUtf8 :: Text -> ByteString
textToBytesUtf8 = Data.Text.Encoding.encodeUtf8

View file

@ -250,6 +250,32 @@ ensureNoneOrSingleRow = \case
List.length more
}
-- | Run a query, passing parameters, and fold over the resulting rows.
--
-- This doesnt have to realize the full list of results in memory,
-- rather results are streamed incrementally from the database.
--
-- When dealing with small results, it may be simpler (and perhaps faster) to use query instead.
--
-- The results are folded strictly into the Monoid returned by the decoder.
--
-- If you need more complex folding logic, use 'foldRowsWith' with a 'Fold'.
--
-- If you can, prefer aggregating in the database itself.
foldRowsWithMonoid ::
forall row params m.
( MonadPostgres m,
PG.ToRow params,
Typeable row,
Typeable params,
Monoid row
) =>
PG.Query ->
params ->
Decoder row ->
Transaction m row
foldRowsWithMonoid qry params decoder = foldRowsWith qry params decoder Fold.mconcat
-- | Run a query, passing parameters, and fold over the resulting rows.
--
-- This doesnt have to realize the full list of results in memory,