From 23056b3b3c587b844176024670c7df4f78eb7f6d Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Tue, 14 Apr 2020 18:24:19 +0000 Subject: [PATCH] DB: Attach a RemoteDiscussion to each RemoteTicket, for caching comments --- config/models | 6 ++++-- migrations/2020_04_10_rt_rd.model | 27 ++++++++++++++++++++++++ src/Vervis/Federation/Ticket.hs | 11 ++++++++-- src/Vervis/Migration.hs | 34 +++++++++++++++++++++++++++++++ src/Vervis/Migration/Model.hs | 8 ++++++++ 5 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 migrations/2020_04_10_rt_rd.model diff --git a/config/models b/config/models index 0f9cd1d..20c02c6 100644 --- a/config/models +++ b/config/models @@ -368,9 +368,11 @@ LocalTicket RemoteTicket ticket TicketAuthorRemoteId ident RemoteObjectId + discuss RemoteDiscussionId - UniqueRemoteTicket ticket - UniqueRemoteTicketIdent ident + UniqueRemoteTicket ticket + UniqueRemoteTicketIdent ident + UniqueRemoteTicketDiscuss discuss TicketProjectLocal ticket TicketId diff --git a/migrations/2020_04_10_rt_rd.model b/migrations/2020_04_10_rt_rd.model new file mode 100644 index 0000000..9951d33 --- /dev/null +++ b/migrations/2020_04_10_rt_rd.model @@ -0,0 +1,27 @@ +Instance + host Host + + UniqueInstance host + +RemoteObject + instance InstanceId + ident LocalURI + + UniqueRemoteObject instance ident + +RemoteTicket + ticket Int64 + ident RemoteObjectId + discuss RemoteDiscussionId + + UniqueRemoteTicket ticket + UniqueRemoteTicketIdent ident + +Discussion + +RemoteDiscussion + ident RemoteObjectId + discuss DiscussionId + + UniqueRemoteDiscussionIdent ident + UniqueRemoteDiscussion discuss diff --git a/src/Vervis/Federation/Ticket.hs b/src/Vervis/Federation/Ticket.hs index 1c68244..710db64 100644 --- a/src/Vervis/Federation/Ticket.hs +++ b/src/Vervis/Federation/Ticket.hs @@ -709,9 +709,16 @@ projectCreateTicketF now shrRecip prjRecip author body ticket muTarget = do { remoteObjectInstance = remoteAuthorInstance author , remoteObjectIdent = luTicket } + did <- insert Discussion + (rdid, rdnew) <- idAndNew <$> insertBy' RemoteDiscussion + { remoteDiscussionIdent = roid + , remoteDiscussionDiscuss = did + } + unless rdnew $ delete did mrtid <- insertUnique RemoteTicket - { remoteTicketTicket = tarid - , remoteTicketIdent = roid + { remoteTicketTicket = tarid + , remoteTicketIdent = roid + , remoteTicketDiscuss = rdid } case mrtid of Nothing -> do diff --git a/src/Vervis/Migration.hs b/src/Vervis/Migration.hs index 5971b69..6d75e42 100644 --- a/src/Vervis/Migration.hs +++ b/src/Vervis/Migration.hs @@ -1518,6 +1518,40 @@ changes hLocal ctx = "RemoteActor" (Nothing :: Maybe Text) "followers" + -- 238 + , addFieldRefRequired'' + "RemoteTicket" + (do iid <- insert $ Instance238 $ Authority "238.fake.fake" Nothing + roid <- insert $ RemoteObject238 iid $ LocalURI "/fake/238" + did <- insert Discussion238 + insertEntity $ RemoteDiscussion238 roid did + ) + (Just $ \ (Entity rdidTemp rdTemp) -> do + rtids <- selectList ([] :: [Filter RemoteTicket238]) [] + for_ rtids $ \ (Entity rtid rt) -> do + let roid = remoteTicket238Ident rt + mrdid <- getKeyBy $ UniqueRemoteDiscussionIdent238 roid + rdid <- + case mrdid of + Nothing -> do + did <- insert Discussion238 + insert $ RemoteDiscussion238 roid did + Just rdid -> return rdid + update rtid [RemoteTicket238Discuss =. rdid] + + delete rdidTemp + + let roidTemp = remoteDiscussion238Ident rdTemp + roTemp <- getJust roidTemp + delete roidTemp + delete $ remoteObject238Instance roTemp + + delete $ remoteDiscussion238Discuss rdTemp + ) + "discuss" + "RemoteDiscussion" + -- 239 + , addUnique "RemoteTicket" $ Unique "UniqueRemoteTicketDiscuss" ["discuss"] ] migrateDB diff --git a/src/Vervis/Migration/Model.hs b/src/Vervis/Migration/Model.hs index 152228f..92ce755 100644 --- a/src/Vervis/Migration/Model.hs +++ b/src/Vervis/Migration/Model.hs @@ -183,6 +183,12 @@ module Vervis.Migration.Model , model_2020_02_22 , model_2020_04_07 , model_2020_04_09 + , RemoteTicket238 + , RemoteTicket238Generic (..) + , Instance238Generic (..) + , RemoteObject238Generic (..) + , Discussion238Generic (..) + , RemoteDiscussion238Generic (..) ) where @@ -363,3 +369,5 @@ model_2020_04_07 = $(schema "2020_04_07_tpra") model_2020_04_09 :: [Entity SqlBackend] model_2020_04_09 = $(schema "2020_04_09_rt") + +makeEntitiesMigration "238" $(modelFile "migrations/2020_04_10_rt_rd.model")