Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion stats/lib/platform-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export const handlePlatformRoutes = async (req, res, pgPools) => {
} else if (req.method === 'GET' && url === '/participants/top-earning') {
await respond(pgPools.stats, fetchTopEarningParticipants)
} else if (req.method === 'GET' && url === '/participants/summary') {
json(res, await fetchParticipantsSummary(pgPools.evaluate))
const summary = await fetchParticipantsSummary(pgPools.evaluate)
res.setHeader('cache-control', `public, max-age=${24 * 3600 /* one day */}`)
json(res, summary)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind extracting these three lines into a new function? I would like to keep handlePlatformRoutes at a single level of abstraction - match request method+path and call the appropriate route handler.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have refactored dc18234 but don't know where to put it. I also don't see a good way to refactor a generic getStatsWithCaching function. Can you please advise in more detail how you envision this?

} else if (req.method === 'GET' && url === '/transfers/daily') {
await respond(pgPools.stats, fetchDailyRewardTransfers)
} else {
Expand Down
4 changes: 4 additions & 0 deletions stats/test/platform-routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ describe('Platform Routes HTTP request handler', () => {
await assertResponseStatus(res, 200)
const summary = await res.json()
assert.deepStrictEqual(summary, { participant_count: 3 })
assert.strictEqual(
res.headers.get('cache-control'),
'public, max-age=86400'
)
})
})
})
Expand Down