0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Fixed comment replies limiting (#15217)

The limit applies to the replies relation is applies globally when
fetching a collection, which means only 3 replies in total will be
fetched across all comments.

This patches the findPage method to manually fetch the replies and
replies adjacent relations manually on each comment, applying the limit
on a comment-by-comment basis.

This is not optimised as we currently still make the initial request for
relations.
This commit is contained in:
Fabien 'egg' O'Carroll 2022-08-11 17:58:43 +01:00 committed by GitHub
parent a0ce5b4b7e
commit ae8cd7c0f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -201,6 +201,25 @@ const Comment = ghostBookshelf.Model.extend({
return options;
},
async findPage(options) {
const {withRelated} = this.defaultRelations('findPage', options);
const relationsToLoadIndividually = [
'replies',
'replies.member',
'replies.count.likes',
'replies.count.liked'
].filter(relation => withRelated.includes(relation));
const result = await ghostBookshelf.Model.findPage.call(this, options);
for (const model of result.data) {
await model.load(relationsToLoadIndividually);
}
return result;
},
countRelations() {
return {
replies(modelOrCollection) {