From bb01d34d8cfd3c8ac071dcc0843a5fe59609180d Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Thu, 13 Aug 2015 21:40:04 +0300 Subject: [PATCH] Avoid duplicate packages on tag page (fixes #116) --- Handler/Tag.hs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Handler/Tag.hs b/Handler/Tag.hs index 3d18fc7..30446df 100644 --- a/Handler/Tag.hs +++ b/Handler/Tag.hs @@ -22,9 +22,12 @@ getTagR :: Slug -> Handler Html getTagR tagSlug = do -- FIXME arguably: check if this tag is banned. Leaving it as displayed for -- now, since someone needs to go out of their way to find it. - tags <- runDB $ selectList [TagTag ==. tagSlug] [Asc TagPackage] - packages <- fmap catMaybes $ forM tags $ \(Entity _ t) -> do - let pname = tagPackage t + packages' <- runDB $ E.select $ E.from $ \tag -> do + E.groupBy (tag E.^. TagPackage) + E.where_ $ tag E.^. TagTag E.==. E.val tagSlug + E.orderBy [E.asc $ tag E.^. TagPackage] + return $ tag E.^. TagPackage + packages <- fmap catMaybes $ forM packages' $ \(E.Value pname) -> do mp <- getPackage $ toPathPiece pname return $ case mp of Nothing -> Nothing