DB: Give each actor a secondary inbox, for collecting errors

This commit is contained in:
Pere Lev 2024-04-27 22:46:37 +03:00
parent ef036fd08b
commit 29e7581b19
No known key found for this signature in database
GPG key ID: 5252C5C863E5E57D
7 changed files with 46 additions and 39 deletions

View file

@ -0,0 +1,18 @@
Outbox
FollowerSet
Inbox
Actor
name Text
desc Text
createdAt UTCTime
inbox InboxId
outbox OutboxId
followers FollowerSetId
justCreatedBy ActorId Maybe
errbox InboxId
UniqueActorInbox inbox
UniqueActorOutbox outbox
UniqueActorFollowers followers

View file

@ -460,18 +460,7 @@ clientCreateDeck now personMeID (ClientMsg maybeCap localRecips remoteRecips fwd
entityKey <$> fromMaybeE mw "Can't find a workflow" entityKey <$> fromMaybeE mw "Can't find a workflow"
insertDeck now name msummary obiidCreate wid actorMeID = do insertDeck now name msummary obiidCreate wid actorMeID = do
ibid <- insert Inbox Entity aid a <- insertActor now name (fromMaybe "" msummary) (Just actorMeID)
obid <- insert Outbox
fsid <- insert FollowerSet
aid <- insert Actor
{ actorName = name
, actorDesc = fromMaybe "" msummary
, actorCreatedAt = now
, actorInbox = ibid
, actorOutbox = obid
, actorFollowers = fsid
, actorJustCreatedBy = Just actorMeID
}
rid <- insert $ Resource aid rid <- insert $ Resource aid
did <- insert Deck did <- insert Deck
{ deckActor = aid { deckActor = aid
@ -481,7 +470,7 @@ clientCreateDeck now personMeID (ClientMsg maybeCap localRecips remoteRecips fwd
, deckWiki = Nothing , deckWiki = Nothing
, deckCreate = obiidCreate , deckCreate = obiidCreate
} }
return (did, rid, fsid) return (did, rid, actorFollowers a)
prepareCreate name msummary deckHash = do prepareCreate name msummary deckHash = do
encodeRouteLocal <- getEncodeRouteLocal encodeRouteLocal <- getEncodeRouteLocal
@ -629,25 +618,14 @@ clientCreateProject now personMeID (ClientMsg maybeCap localRecips remoteRecips
return (name, msummary) return (name, msummary)
insertProject now name msummary obiidCreate actorMeID = do insertProject now name msummary obiidCreate actorMeID = do
ibid <- insert Inbox Entity aid a <- insertActor now name (fromMaybe "" msummary) (Just actorMeID)
obid <- insert Outbox
fsid <- insert FollowerSet
aid <- insert Actor
{ actorName = name
, actorDesc = fromMaybe "" msummary
, actorCreatedAt = now
, actorInbox = ibid
, actorOutbox = obid
, actorFollowers = fsid
, actorJustCreatedBy = Just actorMeID
}
rid <- insert $ Resource aid rid <- insert $ Resource aid
did <- insert Project did <- insert Project
{ projectActor = aid { projectActor = aid
, projectResource = rid , projectResource = rid
, projectCreate = obiidCreate , projectCreate = obiidCreate
} }
return (did, rid, fsid) return (did, rid, actorFollowers a)
prepareCreate name msummary projectHash = do prepareCreate name msummary projectHash = do
encodeRouteLocal <- getEncodeRouteLocal encodeRouteLocal <- getEncodeRouteLocal
@ -795,25 +773,14 @@ clientCreateTeam now personMeID (ClientMsg maybeCap localRecips remoteRecips fwd
return (name, msummary) return (name, msummary)
insertTeam now name msummary obiidCreate actorMeID = do insertTeam now name msummary obiidCreate actorMeID = do
ibid <- insert Inbox Entity aid a <- insertActor now name (fromMaybe "" msummary) (Just actorMeID)
obid <- insert Outbox
fsid <- insert FollowerSet
aid <- insert Actor
{ actorName = name
, actorDesc = fromMaybe "" msummary
, actorCreatedAt = now
, actorInbox = ibid
, actorOutbox = obid
, actorFollowers = fsid
, actorJustCreatedBy = Just actorMeID
}
rid <- insert $ Resource aid rid <- insert $ Resource aid
gid <- insert Group gid <- insert Group
{ groupActor = aid { groupActor = aid
, groupResource = rid , groupResource = rid
, groupCreate = obiidCreate , groupCreate = obiidCreate
} }
return (gid, rid, fsid) return (gid, rid, actorFollowers a)
prepareCreate name msummary groupHash = do prepareCreate name msummary groupHash = do
encodeRouteLocal <- getEncodeRouteLocal encodeRouteLocal <- getEncodeRouteLocal

View file

@ -663,6 +663,7 @@ instance AccountDB AccountPersistDB' where
addNewUser name email key pwd = AccountPersistDB' $ runDB $ do addNewUser name email key pwd = AccountPersistDB' $ runDB $ do
now <- liftIO getCurrentTime now <- liftIO getCurrentTime
ibid <- insert Inbox ibid <- insert Inbox
rbid <- insert Inbox
obid <- insert Outbox obid <- insert Outbox
fsid <- insert FollowerSet fsid <- insert FollowerSet
let actor = Actor let actor = Actor
@ -673,6 +674,7 @@ instance AccountDB AccountPersistDB' where
, actorOutbox = obid , actorOutbox = obid
, actorFollowers = fsid , actorFollowers = fsid
, actorJustCreatedBy = Nothing , actorJustCreatedBy = Nothing
, actorErrbox = rbid
} }
aid <- insert actor aid <- insert actor
let defTime = UTCTime (ModifiedJulianDay 0) 0 let defTime = UTCTime (ModifiedJulianDay 0) 0

View file

@ -3604,6 +3604,20 @@ changes hLocal ctx =
, removeEntity "CollabTopicGroup" , removeEntity "CollabTopicGroup"
-- 624 -- 624
, addFieldPrimRequired "InboxItem" T.empty "result" , addFieldPrimRequired "InboxItem" T.empty "result"
-- 625
, addFieldRefRequired''
"Actor"
(insertEntity Inbox625)
(Just $ \ (Entity tempInboxID Inbox625) -> do
l <- selectKeysList [] []
for_ l $ \ k -> do
inboxID <- insert Inbox625
update k [Actor625Errbox =. inboxID]
delete tempInboxID
)
"errbox"
"Inbox"
] ]
migrateDB migrateDB

View file

@ -66,3 +66,6 @@ makeEntitiesMigration "604"
makeEntitiesMigration "611" makeEntitiesMigration "611"
$(modelFile "migrations/611_2024-04-20_permit_resource.model") $(modelFile "migrations/611_2024-04-20_permit_resource.model")
makeEntitiesMigration "625"
$(modelFile "migrations/625_2024-04-27_errbox.model")

View file

@ -211,6 +211,7 @@ getRemoteActivityURI act = do
insertActor now name desc mby = do insertActor now name desc mby = do
ibid <- insert Inbox ibid <- insert Inbox
rbid <- insert Inbox
obid <- insert Outbox obid <- insert Outbox
fsid <- insert FollowerSet fsid <- insert FollowerSet
let actor = Actor let actor = Actor
@ -221,6 +222,7 @@ insertActor now name desc mby = do
, actorOutbox = obid , actorOutbox = obid
, actorFollowers = fsid , actorFollowers = fsid
, actorJustCreatedBy = mby , actorJustCreatedBy = mby
, actorErrbox = rbid
} }
actorID <- insert actor actorID <- insert actor
return $ Entity actorID actor return $ Entity actorID actor

View file

@ -121,6 +121,7 @@ Actor
outbox OutboxId outbox OutboxId
followers FollowerSetId followers FollowerSetId
justCreatedBy ActorId Maybe justCreatedBy ActorId Maybe
errbox InboxId
UniqueActorInbox inbox UniqueActorInbox inbox
UniqueActorOutbox outbox UniqueActorOutbox outbox