aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-04-17 14:01:06 +0200
committerChocobozzz <me@florianbigard.com>2018-04-17 14:04:34 +0200
commit4195cd2bc5046d4cdf1c677c27cd41f427d7a13a (patch)
tree3300258d96a427da29cc4785686d741e336102bb /server/controllers
parentcff8b272b1631661b8d5f5f4b59bd534ad8c86ca (diff)
downloadPeerTube-4195cd2bc5046d4cdf1c677c27cd41f427d7a13a.tar.gz
PeerTube-4195cd2bc5046d4cdf1c677c27cd41f427d7a13a.tar.zst
PeerTube-4195cd2bc5046d4cdf1c677c27cd41f427d7a13a.zip
Add redis cache to feed route
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/feeds.ts23
1 files changed, 9 insertions, 14 deletions
diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts
index 700c50ec8..3e384c48a 100644
--- a/server/controllers/feeds.ts
+++ b/server/controllers/feeds.ts
@@ -1,16 +1,11 @@
1import * as express from 'express' 1import * as express from 'express'
2import { CONFIG } from '../initializers' 2import { CONFIG, FEEDS } from '../initializers/constants'
3import { 3import { asyncMiddleware, feedsValidator, setDefaultSort, videosSortValidator } from '../middlewares'
4 asyncMiddleware,
5 feedsValidator,
6 setDefaultPagination,
7 setDefaultSort,
8 videosSortValidator
9} from '../middlewares'
10import { VideoModel } from '../models/video/video' 4import { VideoModel } from '../models/video/video'
11import * as Feed from 'pfeed' 5import * as Feed from 'pfeed'
12import { ResultList } from '../../shared/models' 6import { ResultList } from '../../shared/models'
13import { AccountModel } from '../models/account/account' 7import { AccountModel } from '../models/account/account'
8import { cacheRoute } from '../middlewares/cache'
14 9
15const feedsRouter = express.Router() 10const feedsRouter = express.Router()
16 11
@@ -18,6 +13,7 @@ feedsRouter.get('/feeds/videos.:format',
18 videosSortValidator, 13 videosSortValidator,
19 setDefaultSort, 14 setDefaultSort,
20 asyncMiddleware(feedsValidator), 15 asyncMiddleware(feedsValidator),
16 asyncMiddleware(cacheRoute),
21 asyncMiddleware(generateFeed) 17 asyncMiddleware(generateFeed)
22) 18)
23 19
@@ -31,8 +27,7 @@ export {
31 27
32async function generateFeed (req: express.Request, res: express.Response, next: express.NextFunction) { 28async function generateFeed (req: express.Request, res: express.Response, next: express.NextFunction) {
33 let feed = initFeed() 29 let feed = initFeed()
34 const paginationStart = 0 30 const start = 0
35 const paginationCount = 20
36 31
37 let resultList: ResultList<VideoModel> 32 let resultList: ResultList<VideoModel>
38 const account: AccountModel = res.locals.account 33 const account: AccountModel = res.locals.account
@@ -40,15 +35,15 @@ async function generateFeed (req: express.Request, res: express.Response, next:
40 if (account) { 35 if (account) {
41 resultList = await VideoModel.listAccountVideosForApi( 36 resultList = await VideoModel.listAccountVideosForApi(
42 account.id, 37 account.id,
43 paginationStart, 38 start,
44 paginationCount, 39 FEEDS.COUNT,
45 req.query.sort, 40 req.query.sort,
46 true 41 true
47 ) 42 )
48 } else { 43 } else {
49 resultList = await VideoModel.listForApi( 44 resultList = await VideoModel.listForApi(
50 paginationStart, 45 start,
51 paginationCount, 46 FEEDS.COUNT,
52 req.query.sort, 47 req.query.sort,
53 req.query.filter, 48 req.query.filter,
54 true 49 true