DB: Attach a RemoteDiscussion to each RemoteTicket, for caching comments

This commit is contained in:
fr33domlover 2020-04-14 18:24:19 +00:00
parent 6c8b9664a2
commit 23056b3b3c
5 changed files with 82 additions and 4 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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")