Support caching the RSS feed as well
Getty Ritter
5 years ago
39 | 39 |
, filepath >= 1.4.2 && < 1.5
|
40 | 40 |
, xml-types >= 0.3.6 && < 0.4
|
41 | 41 |
, http-types >= 0.12.2 && < 0.13
|
42 | |
, pandoc >= 2.3.1 && < 2.4
|
| 42 |
, pandoc
|
43 | 43 |
, pwstore-fast >= 2.4.4 && < 2.5
|
44 | 44 |
, sqlite-simple >= 0.4.16 && < 0.5
|
45 | 45 |
, stache >= 2.0.1 && < 2.1
|
184 | 184 |
DB.queryMb "SELECT password FROM snap_auth_user WHERE login = ?"
|
185 | 185 |
[DB.f user]
|
186 | 186 |
|
| 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" []
|
187 | 197 |
|
188 | 198 |
cachedMarkup :: PostId -> DB.DB (Maybe T.Text)
|
189 | 199 |
cachedMarkup pId = do
|
|
201 | 211 |
invalidateCachedMarkup :: PostId -> DB.DB ()
|
202 | 212 |
invalidateCachedMarkup pId = do
|
203 | 213 |
DB.execute "DELETE FROM postcache WHERE post_id = ?" [DB.f pId]
|
| 214 |
DB.execute "DELETE FROM rsscache" []
|
3 | 3 |
module Main where
|
4 | 4 |
|
5 | 5 |
import Control.Monad (join)
|
| 6 |
import qualified Data.ByteString.Lazy as BSL
|
6 | 7 |
import qualified Data.Text as TS
|
7 | 8 |
import qualified Data.Text.Encoding as EncodingS
|
8 | 9 |
import qualified Data.Text.Lazy as T
|
|
168 | 169 |
in pure (W.responseFile HTTP.status200 [] path Nothing)
|
169 | 170 |
|
170 | 171 |
("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
|
174 | 180 |
|
175 | 181 |
("GET", [pagename]) -> do
|
176 | 182 |
pg <- DB.runDB c (DB.staticPage pagename)
|