1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-29 02:04:53 +09:00

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