From cc7b12dcd78ce8b3080a23d04afa8d8fb11d7708 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Yuji Date: Sat, 11 Jan 2020 22:26:09 +0900 Subject: [PATCH] Try to fix #277 by deleting verbose info Problem ==== Too slow response from stackage.org/feed/. So slow that my favorite RSS client (Slack's RSS integration) doesn't work due to timeout. See https://github.com/fpco/stackage-server/issues/277 for details. How? ==== Delete the content of the feed if stackage.org/feed is given `withDiff=False` as its query parameter. Why? ==== I can't confirm it's the true cause of the slowdown (because the server is too hard to run on my machine!). But anyway I think the html content of the feed is too much: I just want to know the new LTS Haskell is released by the feed. I'll click the link if I do want to see the detailed updates. In addition, there's a reason generating the content causes the slowdown: Other pages using `getSnapshots` (e.g. https://www.stackage.org/snapshots, https://www.stackage.org/) are not as slow as https://www.stackage.org/feed/. So the `getSnapshots` query dosen't seem to be the biggest cause. And the left possible cause is `mkFeed`. NOTE ==== I've tested nothing because it's too hard to run this app without configuring my AWS account. --- src/Handler/Feed.hs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Handler/Feed.hs b/src/Handler/Feed.hs index 49efc9d..b0c7d5b 100644 --- a/src/Handler/Feed.hs +++ b/src/Handler/Feed.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE QuasiQuotes #-} module Handler.Feed @@ -7,10 +8,11 @@ module Handler.Feed import Data.These import Import +import RIO.Time (getCurrentTime) import Stackage.Database import Stackage.Snapshot.Diff import Text.Blaze (text) -import RIO.Time (getCurrentTime) +import Yesod.Core.Handler (lookupGetParam) getFeedR :: Handler TypedContent getFeedR = track "Handler.Feed.getBranchFeedR" $ getBranchFeed Nothing @@ -25,7 +27,11 @@ mkFeed :: Maybe SnapshotBranch -> [Entity Snapshot] -> Handler TypedContent mkFeed _ [] = notFound mkFeed mBranch snaps = do entries <- forM snaps $ \(Entity snapid snap) -> do - content <- getContent snapid snap + showsDiff <- doesShowDiff + content <- + if showsDiff + then getContent snapid snap + else return mempty return FeedEntry { feedEntryLink = SnapshotR (snapshotName snap) StackageHomeR , feedEntryUpdated = UTCTime (snapshotCreated snap) 0 @@ -54,6 +60,14 @@ mkFeed mBranch snaps = do branchTitle (LtsMajorBranch x) = "LTS-" <> tshow x title = "Recent Stackage " <> maybe "" branchTitle mBranch <> " snapshots" + doesShowDiff = + (fmap fromPathPiece <$> lookupGetParam "withDiff") >>= \case + Just (Just False) -> return False + Just (Just True) -> return True + Just Nothing -> notFound + Nothing -> return True + + getContent :: SnapshotId -> Snapshot -> Handler Html getContent sid2 snap = do mprev <- snapshotBefore $ snapshotName snap