From 5c2e8ecf6840c090c18fb495122d907c134273bf Mon Sep 17 00:00:00 2001 From: Konstantin Zudov Date: Tue, 13 Oct 2015 13:36:37 +0300 Subject: [PATCH] Add /feed/#LtsMajor (e.g /feed/lts-3) --- Handler/Feed.hs | 5 +++++ Stackage/Database.hs | 18 ++++++++++++++++++ config/routes | 1 + 3 files changed, 24 insertions(+) diff --git a/Handler/Feed.hs b/Handler/Feed.hs index 61a7a79..c3d148a 100644 --- a/Handler/Feed.hs +++ b/Handler/Feed.hs @@ -1,6 +1,7 @@ module Handler.Feed ( getFeedR , getLtsFeedR + , getLtsMajorFeedR , getNightlyFeedR ) where @@ -16,10 +17,14 @@ getFeedR = mkFeed . snd =<< getSnapshots 20 0 getLtsFeedR :: Handler TypedContent getLtsFeedR = mkFeed . snd =<< getLtsSnapshots 20 0 +getLtsMajorFeedR :: LtsMajor -> Handler TypedContent +getLtsMajorFeedR (LtsMajor v) = mkFeed . snd =<< getLtsMajorSnapshots v 20 0 + getNightlyFeedR :: Handler TypedContent getNightlyFeedR = mkFeed . snd =<< getNightlySnapshots 20 0 mkFeed :: [Entity Snapshot] -> Handler TypedContent +mkFeed [] = notFound mkFeed snaps = do entries <- forM snaps $ \(Entity snapid snap) -> do content <- getContent snapid snap diff --git a/Stackage/Database.hs b/Stackage/Database.hs index c2576ea..d1c2ac1 100644 --- a/Stackage/Database.hs +++ b/Stackage/Database.hs @@ -34,6 +34,7 @@ module Stackage.Database , getSnapshotsForPackage , getSnapshots , getLtsSnapshots + , getLtsMajorSnapshots , getNightlySnapshots , currentSchema , last5Lts5Nightly @@ -684,6 +685,23 @@ getLtsSnapshots l o = run $ do return snapshot return (ltsCount, snapshots) +getLtsMajorSnapshots :: GetStackageDatabase m + => Int -- ^ Major version + -> Int -- ^ limit + -> Int -- ^ offset + -> m (Int, [Entity Snapshot]) +getLtsMajorSnapshots v l o = run $ do + ltsCount <- count ([] :: [Filter Lts]) + snapshots <- E.select $ E.from $ + \(lts `E.InnerJoin` snapshot) -> do + E.on $ lts E.^. LtsSnap E.==. snapshot E.^. SnapshotId + E.orderBy [E.desc (lts E.^. LtsMinor)] + E.where_ ((lts E.^. LtsMajor) E.==. (E.val v)) + E.limit $ fromIntegral l + E.offset $ fromIntegral o + return snapshot + return (ltsCount, snapshots) + getNightlySnapshots :: GetStackageDatabase m => Int -- ^ limit -> Int -- ^ offset diff --git a/config/routes b/config/routes index 70e126f..5bd3315 100644 --- a/config/routes +++ b/config/routes @@ -47,5 +47,6 @@ /download/#SupportedArch/#Text DownloadGhcLinksR GET /feed FeedR GET +!/feed/#LtsMajor LtsMajorFeedR GET /feed/lts LtsFeedR GET /feed/nightly NightlyFeedR GET