refactor(invitations): insert invitations one at a time
This commit is contained in:
parent
c313ba8097
commit
0044cea857
@ -175,7 +175,7 @@ sinkInvitations :: forall junction.
|
|||||||
-- updated, instead.
|
-- updated, instead.
|
||||||
--
|
--
|
||||||
-- For new junctions an invitation is sent by e-mail.
|
-- For new junctions an invitation is sent by e-mail.
|
||||||
sinkInvitations InvitationConfig{..} = determineExists .| C.foldMap pure >>= lift . sinkInvitations'
|
sinkInvitations InvitationConfig{..} = determineExists .| sinkInvitations'
|
||||||
where
|
where
|
||||||
determineExists :: Conduit (Invitation' junction)
|
determineExists :: Conduit (Invitation' junction)
|
||||||
(YesodJobDB UniWorX)
|
(YesodJobDB UniWorX)
|
||||||
@ -201,13 +201,9 @@ sinkInvitations InvitationConfig{..} = determineExists .| C.foldMap pure >>= lif
|
|||||||
JSON.Success dbData -> return dbData
|
JSON.Success dbData -> return dbData
|
||||||
JSON.Error str -> fail $ "Could not decode invitationData: " <> str
|
JSON.Error str -> fail $ "Could not decode invitationData: " <> str
|
||||||
|
|
||||||
sinkInvitations' :: [Invitation' junction]
|
sinkInvitations' :: Sink (Invitation' junction) (YesodJobDB UniWorX) ()
|
||||||
-> YesodJobDB UniWorX ()
|
sinkInvitations' = do
|
||||||
sinkInvitations' new = do
|
C.mapM_ $ \(jInvitee, fid, dat) -> do
|
||||||
when (is _Nothing (ephemeralInvitation @junction)) $ do
|
|
||||||
insertMany_ $ map (\(email, fid, dat) -> Invitation email (invRef @junction fid) (toJSON $ dat ^. _invitationDBData)) new
|
|
||||||
-- forM_ existing $ \(iid, oldDat) -> update iid [ InvitationData =. toJSON (dat ^. _invitationDBData) ]
|
|
||||||
forM_ new $ \(jInvitee, fid, dat) -> do
|
|
||||||
app <- getYesod
|
app <- getYesod
|
||||||
let mr = renderMessage app $ NonEmpty.toList appLanguages
|
let mr = renderMessage app $ NonEmpty.toList appLanguages
|
||||||
ur <- getUrlRenderParams
|
ur <- getUrlRenderParams
|
||||||
@ -224,6 +220,8 @@ sinkInvitations InvitationConfig{..} = determineExists .| C.foldMap pure >>= lif
|
|||||||
jInvitationSubject <- fmap mr . mapReaderT liftHandlerT $ invitationSubject fEnt dat
|
jInvitationSubject <- fmap mr . mapReaderT liftHandlerT $ invitationSubject fEnt dat
|
||||||
let jInvitationExplanation = invitationExplanation fEnt dat (toHtml . mr) ur
|
let jInvitationExplanation = invitationExplanation fEnt dat (toHtml . mr) ur
|
||||||
|
|
||||||
|
when (is _Nothing (ephemeralInvitation @junction)) $ insert_ $ Invitation jInvitee (invRef @junction fid) (toJSON $ dat ^. _invitationDBData)
|
||||||
|
|
||||||
queueDBJob JobInvitation{..}
|
queueDBJob JobInvitation{..}
|
||||||
|
|
||||||
sinkInvitationsF :: forall junction mono.
|
sinkInvitationsF :: forall junction mono.
|
||||||
|
|||||||
Reference in New Issue
Block a user