DB: Simplify ComponentGather using the new DestUsStart

This commit is contained in:
Pere Lev 2024-04-14 15:21:56 +03:00
parent b47941af97
commit 8024e993a2
No known key found for this signature in database
GPG key ID: 5252C5C863E5E57D
5 changed files with 28 additions and 30 deletions

View file

@ -0,0 +1,7 @@
ComponentGather
component ComponentEnableId
parent DestUsStartId
grant OutboxItemId
UniqueComponentGather component parent
UniqueComponentGatherGrant grant

View file

@ -3345,9 +3345,7 @@ projectGrant now projectID (Verse authorIdMsig body) grant = do
) )
localExtensions <- lift $ for localComponents $ \ (E.Value startID, Entity componentID component, Entity enableID _) -> do localExtensions <- lift $ for localComponents $ \ (E.Value startID, Entity componentID component, Entity enableID _) -> do
extID <- insertEmptyOutboxItem' (actorOutbox recipActor) now extID <- insertEmptyOutboxItem' (actorOutbox recipActor) now
case to of insert_ $ ComponentGather enableID destStartID extID
Left localID -> insert_ $ ComponentGatherLocal enableID localID extID
Right remoteID -> insert_ $ ComponentGatherRemote enableID remoteID extID
componentIdent <- do componentIdent <- do
i <- getComponentIdent componentID i <- getComponentIdent componentID
bitraverse bitraverse
@ -3382,9 +3380,7 @@ projectGrant now projectID (Verse authorIdMsig body) grant = do
) )
remoteExtensions <- lift $ for remoteComponents $ \ (E.Value startID, Entity componentID component, Entity enableID _) -> do remoteExtensions <- lift $ for remoteComponents $ \ (E.Value startID, Entity componentID component, Entity enableID _) -> do
extID <- insertEmptyOutboxItem' (actorOutbox recipActor) now extID <- insertEmptyOutboxItem' (actorOutbox recipActor) now
case to of insert_ $ ComponentGather enableID destStartID extID
Left localID -> insert_ $ ComponentGatherLocal enableID localID extID
Right remoteID -> insert_ $ ComponentGatherRemote enableID remoteID extID
componentIdent <- do componentIdent <- do
i <- getComponentIdent componentID i <- getComponentIdent componentID
bitraverse bitraverse
@ -4581,11 +4577,7 @@ projectRemove now projectID (Verse authorIdMsig body) remove = do
lift $ for maybeRemoveDB $ \ _removeDB -> do lift $ for maybeRemoveDB $ \ _removeDB -> do
-- Delete uses of this Dest from my Component records -- Delete uses of this Dest from my Component records
case topic of deleteWhere [ComponentGatherParent ==. destStartID]
Left (_, _, sendID) ->
deleteWhere [ComponentGatherLocalParent ==. sendID]
Right (_, sendID) ->
deleteWhere [ComponentGatherRemoteParent ==. sendID]
-- Delete uses of this Dest from my Source records -- Delete uses of this Dest from my Source records
gatherIDs <- selectKeysList [SourceUsGatherDest ==. destStartID] [] gatherIDs <- selectKeysList [SourceUsGatherDest ==. destStartID] []
@ -4996,15 +4988,12 @@ projectRevoke now projectID (Verse authorIdMsig body) (AP.Revoke (luFirst :| lus
maybeRevokeDB <- lift $ insertToInbox now authorIdMsig body (actorInbox actorRecip) False maybeRevokeDB <- lift $ insertToInbox now authorIdMsig body (actorInbox actorRecip) False
lift $ for maybeRevokeDB $ \ _revokeDB -> do lift $ for maybeRevokeDB $ \ _revokeDB -> do
-- Delete uses of this Dest from my Component records
case send of
Left sendID ->
deleteWhere [ComponentGatherLocalParent ==. sendID]
Right sendID ->
deleteWhere [ComponentGatherRemoteParent ==. sendID]
maybeStartID <- getKeyBy $ UniqueDestUsStart usAcceptID maybeStartID <- getKeyBy $ UniqueDestUsStart usAcceptID
-- Delete uses of this Dest from my Component records
for_ maybeStartID $ \ destStartID ->
deleteWhere [ComponentGatherParent ==. destStartID]
-- Delete uses of this Dest from my Source records -- Delete uses of this Dest from my Source records
for_ maybeStartID $ \ destStartID -> do for_ maybeStartID $ \ destStartID -> do
gatherIDs <- selectKeysList [SourceUsGatherDest ==. destStartID] [] gatherIDs <- selectKeysList [SourceUsGatherDest ==. destStartID] []

View file

@ -3247,6 +3247,12 @@ changes hLocal ctx =
, removeEntity "SourceUsGatherToLocal" , removeEntity "SourceUsGatherToLocal"
-- 588 -- 588
, removeEntity "SourceUsGatherToRemote" , removeEntity "SourceUsGatherToRemote"
-- 589
, removeEntity "ComponentGatherLocal"
-- 590
, removeEntity "ComponentGatherRemote"
-- 591
, addEntities model_591_component_gather
] ]
migrateDB migrateDB

View file

@ -71,6 +71,7 @@ module Vervis.Migration.Entities
, model_577_component_gather , model_577_component_gather
, model_578_source_remove , model_578_source_remove
, model_583_dest_start , model_583_dest_start
, model_591_component_gather
) )
where where
@ -276,3 +277,6 @@ model_578_source_remove = $(schema "578_2024-04-03_source_remove")
model_583_dest_start :: [Entity SqlBackend] model_583_dest_start :: [Entity SqlBackend]
model_583_dest_start = $(schema "583_2024-04-13_dest_start") model_583_dest_start = $(schema "583_2024-04-13_dest_start")
model_591_component_gather :: [Entity SqlBackend]
model_591_component_gather = $(schema "591_2024-04-14_component_gather")

View file

@ -1104,21 +1104,13 @@ ComponentFurtherRemote
-- Witnesses that the project has extended a given delegation to a given -- Witnesses that the project has extended a given delegation to a given
-- parent -- parent
ComponentGatherLocal ComponentGather
component ComponentEnableId component ComponentEnableId
parent DestThemSendDelegatorLocalId parent DestUsStartId
grant OutboxItemId grant OutboxItemId
UniqueComponentGatherLocal component parent UniqueComponentGather component parent
UniqueComponentGatherLocalGrant grant UniqueComponentGatherGrant grant
ComponentGatherRemote
component ComponentEnableId
parent DestThemSendDelegatorRemoteId
grant OutboxItemId
UniqueComponentGatherRemote component parent
UniqueComponentGatherRemoteGrant grant
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- Components, from component perspective -- Components, from component perspective