From 9ebfd210be02adf7804388590ee58890000e7faa Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan <ram@leastauthority.com> Date: Thu, 24 Oct 2019 12:23:54 +0530 Subject: [PATCH] isVoucherUnpaid: fix an incorrect sql statement Vouchers table contain all paid vouchers, so to find if a given voucher is unpaid, all we need to do is check membership in the `vouchers' table. --- src/PaymentServer/Persistence.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PaymentServer/Persistence.hs b/src/PaymentServer/Persistence.hs index 1317d90..a54302e 100644 --- a/src/PaymentServer/Persistence.hs +++ b/src/PaymentServer/Persistence.hs @@ -134,7 +134,7 @@ instance FromRow Fingerprint where -- | Checks if the given `voucher` is unpaid. isVoucherUnpaid :: Sqlite.Connection -> Voucher -> IO Bool isVoucherUnpaid dbConn voucher = - null <$> (Sqlite.query dbConn "SELECT DISTINCT name FROM vouchers INNER JOIN redeemed WHERE vouchers.id != redeemed.voucher_id AND vouchers.name = ?" (Sqlite.Only voucher) :: IO [Voucher]) + null <$> (Sqlite.query dbConn "SELECT 1 FROM vouchers WHERE vouchers.name = ? LIMIT 1" (Sqlite.Only voucher) :: IO [Voucher]) getVoucherFingerprint :: Sqlite.Connection -> Voucher -> IO [Fingerprint] getVoucherFingerprint dbConn voucher = -- GitLab