Skip to content
Snippets Groups Projects
Commit 495b5492 authored by Ramakrishnan Muthukrishnan's avatar Ramakrishnan Muthukrishnan
Browse files

do the read/write operations from the db should be in a transaction

`redeemVoucher' reads stuff from the db, makes decisions and then
writes to the db. However if there is another client doing a
simultaneous `redeemVoucher' for the same `voucher', then both of them
would redeem the voucher, which is incorrect. The operations should
have exclusive access to the db and this is achieved with
`withExclusiveTransaction`.
parent 392fda8c
No related branches found
No related tags found
1 merge request!26Initial implementation of Persistence using sqlite
......@@ -101,7 +101,7 @@ instance VoucherDatabase VoucherDatabaseState where
let insertFn = (modifyIORef redeemed .) . Map.insert
redeemVoucherHelper (unpaid, existingFingerprint) voucher fingerprint insertFn
redeemVoucher SQLiteDB { conn = conn } voucher fingerprint = do
redeemVoucher SQLiteDB { conn = conn } voucher fingerprint = Sqlite.withExclusiveTransaction conn $ do
unpaid <- isVoucherUnpaid conn voucher
existingFingerprint <- getVoucherFingerprint conn voucher
let insertFn = insertVoucherAndFingerprint conn
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment