Removed deleted and hidden comments from the comment count

refs https://github.com/TryGhost/Team/issues/1763

These should not be included in the count as they do not contain content.
This commit is contained in:
Fabien 'egg' O'Carroll 2022-08-09 13:51:13 +01:00 committed by GitHub
parent fd9e19ce07
commit 43d41e8b0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,7 @@ module.exports = class CommentsStatsService {
const results = await this.db.knex('comments') const results = await this.db.knex('comments')
.select(this.db.knex.raw(`COUNT(*) AS count, post_id`)) .select(this.db.knex.raw(`COUNT(*) AS count, post_id`))
.groupBy('post_id') .groupBy('post_id')
.where('status', 'published')
.whereIn('post_id', ids); .whereIn('post_id', ids);
const counts = ids.reduce((memo, id) => { const counts = ids.reduce((memo, id) => {
@ -30,6 +31,7 @@ module.exports = class CommentsStatsService {
async getAllCounts() { async getAllCounts() {
const results = await this.db.knex('comments') const results = await this.db.knex('comments')
.select(this.db.knex.raw(`COUNT(*) AS count, post_id`)) .select(this.db.knex.raw(`COUNT(*) AS count, post_id`))
.where('status', 'published')
.groupBy('post_id'); .groupBy('post_id');
/** @type Object<string, number> */ /** @type Object<string, number> */