gdritter repos new-inf-blog / 78f200d
Support caching the RSS feed as well Getty Ritter 5 years ago
3 changed file(s) with 21 addition(s) and 4 deletion(s). Collapse all Expand all
3939 , filepath >= 1.4.2 && < 1.5
4040 , xml-types >= 0.3.6 && < 0.4
4141 , http-types >= 0.12.2 && < 0.13
42 , pandoc >= 2.3.1 && < 2.4
42 , pandoc
4343 , pwstore-fast >= 2.4.4 && < 2.5
4444 , sqlite-simple >= 0.4.16 && < 0.5
4545 , stache >= 2.0.1 && < 2.1
184184 DB.queryMb "SELECT password FROM snap_auth_user WHERE login = ?"
185185 [DB.f user]
186186
187 storeCachedRSS :: BS.ByteString -> DB.DB ()
188 storeCachedRSS prerendered = do
189 DB.execute
190 "INSERT INTO rsscache (prerendered) VALUES (?)"
191 [DB.f prerendered]
192
193 cachedRSS :: DB.DB (Maybe BS.ByteString)
194 cachedRSS = do
195 fmap DB.fromOnly <$>
196 DB.queryMb "SELECT prerendered FROM rsscache" []
187197
188198 cachedMarkup :: PostId -> DB.DB (Maybe T.Text)
189199 cachedMarkup pId = do
201211 invalidateCachedMarkup :: PostId -> DB.DB ()
202212 invalidateCachedMarkup pId = do
203213 DB.execute "DELETE FROM postcache WHERE post_id = ?" [DB.f pId]
214 DB.execute "DELETE FROM rsscache" []
33 module Main where
44
55 import Control.Monad (join)
6 import qualified Data.ByteString.Lazy as BSL
67 import qualified Data.Text as TS
78 import qualified Data.Text.Encoding as EncodingS
89 import qualified Data.Text.Lazy as T
168169 in pure (W.responseFile HTTP.status200 [] path Nothing)
169170
170171 ("GET", ["rss"]) -> do
171 posts <- DB.runDB c DB.allPosts
172 feed <- Feed.renderFeed posts
173 Web.atomFeed feed
172 cached <- DB.runDB c DB.cachedRSS
173 case cached of
174 Just t -> Web.atomFeed (BSL.fromStrict t)
175 Nothing -> do
176 posts <- DB.runDB c DB.allPosts
177 feed <- Feed.renderFeed posts
178 DB.runDB c (DB.storeCachedRSS (BSL.toStrict feed))
179 Web.atomFeed feed
174180
175181 ("GET", [pagename]) -> do
176182 pg <- DB.runDB c (DB.staticPage pagename)