Use updateGet for atomic access to projectNextTicket

`updateGet` isn't atomic by default. In PostgreSQL the default isolation level
if committed read, and an `update` followed by a `get` doesn't guarantee you
get the same value you sent. However I'm making a patch for `persistent` to
make `updateGet` atomic for PostgreSQL.
This commit is contained in:
fr33domlover 2019-06-18 10:47:01 +00:00
parent fb909adf2e
commit 1ae924558f

View file

@ -179,10 +179,9 @@ projectOfferTicketF
findRelevantCollections hLocal $
activityAudience $ actbActivity body
mremotesHttp <- runDBExcept $ do
(sid, jid, ibid, fsid, next, tids) <-
getProjectAndDeps deps
(sid, jid, ibid, fsid, tids) <- getProjectAndDeps deps
lift $ join <$> do
mractid <- insertTicket jid ibid next tids
mractid <- insertTicket jid ibid tids
for mractid $ \ ractid -> for msig $ \ sig -> do
remoteRecips <- deliverLocal ractid colls sid fsid
(sig,) <$> deliverRemoteDB (actbBL body) ractid jid sig remoteRecips
@ -234,11 +233,8 @@ projectOfferTicketF
tids <- for deps $ \ dep -> do
mtid <- lift $ getKeyBy $ UniqueTicket jid dep
fromMaybeE mtid "Local dep: No such ticket number in DB"
return
( sid, jid, projectInbox j, projectFollowers j, projectNextTicket j
, tids
)
insertTicket jid ibid next deps = do
return (sid, jid, projectInbox j, projectFollowers j, tids)
insertTicket jid ibid deps = do
let iidAuthor = remoteAuthorInstance author
raidAuthor = remoteAuthorId author
ractid <- either entityKey id <$> insertBy' RemoteActivity
@ -254,7 +250,9 @@ projectOfferTicketF
delete ibiid
return Nothing
Just _ibirid -> do
update jid [ProjectNextTicket +=. 1]
next <-
((subtract 1) . projectNextTicket) <$>
updateGet jid [ProjectNextTicket +=. 1]
did <- insert Discussion
fsid <- insert FollowerSet
tid <- insert Ticket