From 9752f27afb08f28403f2719f8944fb5bb9cbea3c Mon Sep 17 00:00:00 2001 From: nek0 Date: Fri, 15 Apr 2022 19:09:44 +0200 Subject: [PATCH] modernize join --- src/Model/Product.hs | 58 ++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 42 deletions(-) diff --git a/src/Model/Product.hs b/src/Model/Product.hs index d75d0b5..362cde5 100644 --- a/src/Model/Product.hs +++ b/src/Model/Product.hs @@ -134,48 +134,22 @@ produceProductOverviews ) produceProductOverviews refine = proc () -> do - (p, i2, i6, i6a, i7, i8, i9, i11, i12, i13, a3, a4) - <- orderBy (asc (\(_, a2, _, _, _, _, _, _, _, _, _, _) -> a2)) (leftJoinF - (\(pid, pi2, pi6, pi6a, pi7, pi8, pi9, pi11, pi12, pi13) - (_, _, ai3, ai4, _) -> - (pid, pi2, pi6, pi6a, pi7, pi8, pi9, pi11, pi12, pi13, ai3, ai4) - ) - (const - ( toFields (0 :: Int) :: Column SqlInt4 - , toFields ("ERROR PRODUCT" :: T.Text) :: Column SqlText - , toFields (0 :: Int) :: Column SqlInt4 - , toFields (Just (0 :: Int)) :: Column (Nullable SqlInt4) - , toFields (Just (0 :: Int)) :: Column (Nullable SqlInt4) - , toFields (0 :: Int) :: Column SqlInt4 - , toFields (0 :: Int) :: Column SqlInt4 - , toFields (0 :: Int) :: Column SqlInt4 - , toFields (Just (0 :: Int)) :: Column (Nullable SqlInt4) - , toFields (Just ("" :: T.Text)) :: Column (Nullable SqlText) - , toFields (0 :: Int) :: Column SqlInt4 - , toFields (0 :: Int) :: Column SqlInt4 - ) - ) - (\(pid, _, _, _, _, _, _, _, _, _) - (aid, _, _, _, _) -> - pid .== aid - ) - (selectTable productTable) - (joinF - (\(_, _, a3, a4, a5) (b1, b2) -> - (b1, b2, a3, a4, a5) - ) - (\(a1, a2, _, _, _) (b1, b2) -> - (a1 .== b1) .&& (a2 .== b2) - ) - (selectTable amountTable) - (aggregate - ((,) - <$> P.lmap fst O.groupBy - <*> P.lmap snd O.max - ) - (arr (\(a, b, _, _, _) -> (a, b)) <<< selectTable amountTable)) - )) -< () - -- <<< arr (\_ -> (selectTable productTable, selectTable amountTable)) -< () + (p, i2, i6, i6a, i7, i8, i9, i11, i12, i13) <- + selectTable productTable -< () + (_, _, a3, a4, _) <- do + (a1, a2, a3, a4, a5) <- selectTable amountTable -< () + (b1, b2) <- do + (ib1, ib2, _, _, _) <- selectTable amountTable -< () + (laterally . aggregate) + ( + (,) + <$> P.lmap fst O.groupBy + <*> P.lmap snd O.max + ) + (arr (\(ib1, ib2, _, _, _) -> (ib1, ib2)) <<< selectTable amountTable ) -< () + returnA -< (ib1, ib2) + restrict -< a1 .== b1 .&& a2 .== b2 + returnA -< (b1, b2, a3, a4, a5) restrict -< case refine of AllProducts -> toFields True AvailableProducts -> a3 ./= (toFields (0 :: Int) :: Column SqlInt4)