From 1af7ff1c7dbe5c338405bbb46d0d03bb4f1d8bcd Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <ram@leastauthority.com>
Date: Thu, 17 Oct 2019 19:36:57 +0530
Subject: [PATCH] use the `isVoucherUnpaid` function instead of the logic with
 Sets

---
 src/PaymentServer/Persistence.hs | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/PaymentServer/Persistence.hs b/src/PaymentServer/Persistence.hs
index 26f7df1..f332786 100644
--- a/src/PaymentServer/Persistence.hs
+++ b/src/PaymentServer/Persistence.hs
@@ -117,7 +117,7 @@ instance VoucherDatabase Sqlite.Connection where
     undefined
   -- redeemVoucher :: Sqlite.Connection -> Voucher -> Fingerprint -> IO (Either RedeemError ())
   redeemVoucher dbConn voucher fingerprint = do
-    unpaid <- Set.notMember voucher <$> (Set.fromList <$> getUnredeemedVouchers dbConn)
+    unpaid <- isVoucherUnpaid dbConn voucher
     existingFingerprint <- getVoucherFingerprint dbConn voucher
     case (unpaid, existingFingerprint) of
       (True, _) ->
@@ -135,11 +135,7 @@ instance FromRow Fingerprint where
   fromRow = Sqlite.field
 
 
--- | All paid but not redeemed vouchers
-getUnredeemedVouchers :: Sqlite.Connection -> IO [Voucher]
-getUnredeemedVouchers dbConn =
-  Sqlite.query_ dbConn "SELECT DISTINCT name FROM vouchers INNER JOIN redeemed WHERE vouchers.id != redeemed.voucher_id"
-
+-- | Checks if the given `voucher` is unpaid.
 isVoucherUnpaid :: Sqlite.Connection -> Voucher -> IO Bool
 isVoucherUnpaid dbConn voucher = do
   results <- 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]
-- 
GitLab