From 8024e993a25bd8b82806a870587db66f9839378d Mon Sep 17 00:00:00 2001 From: Pere Lev Date: Sun, 14 Apr 2024 15:21:56 +0300 Subject: [PATCH] DB: Simplify ComponentGather using the new DestUsStart --- .../591_2024-04-14_component_gather.model | 7 ++++++ src/Vervis/Actor/Project.hs | 25 ++++++------------- src/Vervis/Migration.hs | 6 +++++ src/Vervis/Migration/Entities.hs | 4 +++ th/models | 16 +++--------- 5 files changed, 28 insertions(+), 30 deletions(-) create mode 100644 migrations/591_2024-04-14_component_gather.model diff --git a/migrations/591_2024-04-14_component_gather.model b/migrations/591_2024-04-14_component_gather.model new file mode 100644 index 0000000..e2c542e --- /dev/null +++ b/migrations/591_2024-04-14_component_gather.model @@ -0,0 +1,7 @@ +ComponentGather + component ComponentEnableId + parent DestUsStartId + grant OutboxItemId + + UniqueComponentGather component parent + UniqueComponentGatherGrant grant diff --git a/src/Vervis/Actor/Project.hs b/src/Vervis/Actor/Project.hs index adf0623..1e0d2f5 100644 --- a/src/Vervis/Actor/Project.hs +++ b/src/Vervis/Actor/Project.hs @@ -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 extID <- insertEmptyOutboxItem' (actorOutbox recipActor) now - case to of - Left localID -> insert_ $ ComponentGatherLocal enableID localID extID - Right remoteID -> insert_ $ ComponentGatherRemote enableID remoteID extID + insert_ $ ComponentGather enableID destStartID extID componentIdent <- do i <- getComponentIdent componentID 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 extID <- insertEmptyOutboxItem' (actorOutbox recipActor) now - case to of - Left localID -> insert_ $ ComponentGatherLocal enableID localID extID - Right remoteID -> insert_ $ ComponentGatherRemote enableID remoteID extID + insert_ $ ComponentGather enableID destStartID extID componentIdent <- do i <- getComponentIdent componentID bitraverse @@ -4581,11 +4577,7 @@ projectRemove now projectID (Verse authorIdMsig body) remove = do lift $ for maybeRemoveDB $ \ _removeDB -> do -- Delete uses of this Dest from my Component records - case topic of - Left (_, _, sendID) -> - deleteWhere [ComponentGatherLocalParent ==. sendID] - Right (_, sendID) -> - deleteWhere [ComponentGatherRemoteParent ==. sendID] + deleteWhere [ComponentGatherParent ==. destStartID] -- Delete uses of this Dest from my Source records 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 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 + -- Delete uses of this Dest from my Component records + for_ maybeStartID $ \ destStartID -> + deleteWhere [ComponentGatherParent ==. destStartID] + -- Delete uses of this Dest from my Source records for_ maybeStartID $ \ destStartID -> do gatherIDs <- selectKeysList [SourceUsGatherDest ==. destStartID] [] diff --git a/src/Vervis/Migration.hs b/src/Vervis/Migration.hs index 83ab062..3ae904a 100644 --- a/src/Vervis/Migration.hs +++ b/src/Vervis/Migration.hs @@ -3247,6 +3247,12 @@ changes hLocal ctx = , removeEntity "SourceUsGatherToLocal" -- 588 , removeEntity "SourceUsGatherToRemote" + -- 589 + , removeEntity "ComponentGatherLocal" + -- 590 + , removeEntity "ComponentGatherRemote" + -- 591 + , addEntities model_591_component_gather ] migrateDB diff --git a/src/Vervis/Migration/Entities.hs b/src/Vervis/Migration/Entities.hs index f66647f..7f95ab1 100644 --- a/src/Vervis/Migration/Entities.hs +++ b/src/Vervis/Migration/Entities.hs @@ -71,6 +71,7 @@ module Vervis.Migration.Entities , model_577_component_gather , model_578_source_remove , model_583_dest_start + , model_591_component_gather ) 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 = $(schema "583_2024-04-13_dest_start") + +model_591_component_gather :: [Entity SqlBackend] +model_591_component_gather = $(schema "591_2024-04-14_component_gather") diff --git a/th/models b/th/models index 037caa1..66794fa 100644 --- a/th/models +++ b/th/models @@ -1104,21 +1104,13 @@ ComponentFurtherRemote -- Witnesses that the project has extended a given delegation to a given -- parent -ComponentGatherLocal +ComponentGather component ComponentEnableId - parent DestThemSendDelegatorLocalId + parent DestUsStartId grant OutboxItemId - UniqueComponentGatherLocal component parent - UniqueComponentGatherLocalGrant grant - -ComponentGatherRemote - component ComponentEnableId - parent DestThemSendDelegatorRemoteId - grant OutboxItemId - - UniqueComponentGatherRemote component parent - UniqueComponentGatherRemoteGrant grant + UniqueComponentGather component parent + UniqueComponentGatherGrant grant ------------------------------------------------------------------------------ -- Components, from component perspective