refactor(users/Profpatsch/whatcd-resolver): move inserts out

Now we can move the I/O into a where block.

Change-Id: Ib5334948f3d11ca120ce0b7a46c67f8500fdab3a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9484
Reviewed-by: Profpatsch <mail@profpatsch.de>
Tested-by: BuildkiteCI
Autosubmit: Profpatsch <mail@profpatsch.de>
This commit is contained in:
Profpatsch 2023-09-27 23:27:12 +02:00 committed by clbot
parent 7157e2baed
commit 7bc739ec5f

View file

@ -707,7 +707,24 @@ redactedSearchAndInsert extraArguments = do
<&> Json.Object <&> Json.Object
) )
let tourGroup = T3 groupId groupName fullJsonResult let tourGroup = T3 groupId groupName fullJsonResult
let insertTourGroup dat = do torrents <- Json.key "torrents" $
Json.eachInArray $ do
torrentId <- Json.keyLabel @"torrentId" "torrentId" (Json.asIntegral @_ @Int)
fullJsonResultT <- label @"fullJsonResult" <$> Json.asValue
pure $ T2 torrentId fullJsonResultT
pure
( insertTourGroup tourGroup
>>= (\tg -> insertTorrents (T2 (getLabel @"tourGroupIdPg" tg) (label @"torrents" torrents)))
)
)
pure
( T2
(label @"pages" pages)
(label @"transaction" transaction)
)
)
where
insertTourGroup dat = do
_ <- _ <-
execute execute
[fmt| [fmt|
@ -734,12 +751,8 @@ redactedSearchAndInsert extraArguments = do
] ]
(label @"tourGroupIdPg" <$> Dec.fromField @Int) (label @"tourGroupIdPg" <$> Dec.fromField @Int)
>>= ensureSingleRow >>= ensureSingleRow
torrents <- Json.key "torrents" $
Json.eachInArray $ do insertTorrents dat = do
torrentId <- Json.keyLabel @"torrentId" "torrentId" (Json.asIntegral @_ @Int)
fullJsonResultT <- label @"fullJsonResult" <$> Json.asValue
pure $ T2 torrentId fullJsonResultT
let insertTorrents dat = do
_ <- _ <-
execute execute
[sql| [sql|
@ -764,17 +777,6 @@ redactedSearchAndInsert extraArguments = do
) )
) )
pure () pure ()
pure
( insertTourGroup tourGroup
>>= (\tg -> insertTorrents (T2 (getLabel @"tourGroupIdPg" tg) (label @"torrents" torrents)))
)
)
pure
( T2
(label @"pages" pages)
(label @"transaction" transaction)
)
)
redactedGetTorrentFileAndInsert :: redactedGetTorrentFileAndInsert ::
( HasField "torrentId" r Int, ( HasField "torrentId" r Int,