Ensured comment counts route doesn't load member (#19762)

refs https://linear.app/tryghost/issue/ENG-672/

The comment counts endpoint does not need member authentication.
This saves us a bunch of db queries for each request
This commit is contained in:
Fabien 'egg' O'Carroll 2024-02-28 07:36:35 +07:00 committed by GitHub
parent 7f392c305b
commit 5fae212416
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,15 +11,15 @@ module.exports = function apiRoutes() {
const router = express.Router('comment api');
router.use(bodyParser.json({limit: '50mb'}));
// Global handling for member session, ensures a member is logged in to the frontend
router.use(membersService.middleware.loadMemberSession);
const countsCache = shared.middleware.cacheControl(
'public',
{maxAge: config.get('caching:commentsCountAPI:maxAge')}
);
router.get('/counts', countsCache, http(api.commentsMembers.counts));
// Authenticated Routes
router.use(membersService.middleware.loadMemberSession);
router.get('/', http(api.commentsMembers.browse));
router.get('/:id', http(api.commentsMembers.read));
router.post('/', http(api.commentsMembers.add));