From 61b094e3e69ba17c05b21613760cbfaf8425693d Mon Sep 17 00:00:00 2001 From: nek0 Date: Fri, 9 Aug 2019 20:55:57 +0200 Subject: [PATCH] limit the returned rows --- src/Model/Amount.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Model/Amount.hs b/src/Model/Amount.hs index fa9b1a8..0ce9556 100644 --- a/src/Model/Amount.hs +++ b/src/Model/Amount.hs @@ -83,7 +83,7 @@ getLatestPriceByProductId -> MateHandler Int -- The price in cents getLatestPriceByProductId pid conn = do amounts <- liftIO $ runSelect conn $ - orderBy (desc (\(_, ts, _, _, _) -> ts)) + limit 1 $ orderBy (desc (\(_, ts, _, _, _) -> ts)) (keepWhen (\(id_, _, _, _, _) -> id_ .== C.constant pid) <<< queryTable amountTable) :: MateHandler [ ( Int @@ -103,7 +103,7 @@ getLatestAmountByProductId -> MateHandler Int -- The amount getLatestAmountByProductId pid conn = do amounts <- liftIO $ runSelect conn $ - orderBy (desc (\(_, ts, _, _, _) -> ts)) + limit 1 $ orderBy (desc (\(_, ts, _, _, _) -> ts)) (keepWhen (\(id_, _, _, _, _) -> id_ .== C.constant pid) <<< queryTable amountTable) :: MateHandler [ ( Int @@ -124,7 +124,7 @@ getLatestTotalPrice -> MateHandler Int -- The price in cents getLatestTotalPrice (PurchaseDetail pid amount) conn = do amounts <- liftIO $ runSelect conn $ - orderBy (desc (\(_, ts, _, _, _) -> ts)) $ + limit 1 $ orderBy (desc (\(_, ts, _, _, _) -> ts)) $ keepWhen (\(id_, _, _, _, _) -> id_ .== C.constant pid) <<< queryTable amountTable :: MateHandler @@ -146,7 +146,7 @@ checkProductAvailability -> MateHandler (Maybe Int) -- | Returns maybe missing amount checkProductAvailability (PurchaseDetail pid amount) conn = do realamount <- (\(_, _, ramount, _, _) -> ramount) <$> head <$> - (liftIO $ runSelect conn $ + (liftIO $ runSelect conn $ limit 1 $ orderBy (desc (\(_, ts, _, _, _) -> ts)) $ keepWhen (\(id_, _, _, _, _) -> id_ .== C.constant pid) <<< queryTable amountTable @@ -230,7 +230,7 @@ postBuyProductAmountUpdate postBuyProductAmountUpdate (PurchaseDetail pid pdamount) conn = do now <- liftIO $ getCurrentTime (amount, oldprice) <- (\(_, _, am, op, _) -> (am, op)) <$> head <$> ( - liftIO $ runSelect conn $ + liftIO $ runSelect conn $ limit 1 $ orderBy (desc (\(_, ts, _, _, _) -> ts)) $ keepWhen (\(id_, _, _, _, _) -> id_ .== C.constant pid) <<< queryTable amountTable