From a696ef9be5551db9ec360913ff73226266561d49 Mon Sep 17 00:00:00 2001 From: Nick Funk Date: Wed, 4 Sep 2019 10:43:00 -0600 Subject: [PATCH] [CORL-572] Filter rejected comments from reply counts on user comment history (#2516) * Filter rejected comments from reply counts on user comment history CORL-572 * fix: use cache to improve performance * fix: added TODO --- src/core/server/graph/tenant/resolvers/Comment.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/core/server/graph/tenant/resolvers/Comment.ts b/src/core/server/graph/tenant/resolvers/Comment.ts index 60da0d28a..53e14e7fc 100644 --- a/src/core/server/graph/tenant/resolvers/Comment.ts +++ b/src/core/server/graph/tenant/resolvers/Comment.ts @@ -14,6 +14,7 @@ import * as comment from "coral-server/models/comment"; import { getLatestRevision, hasAncestors, + hasPublishedStatus, } from "coral-server/models/comment/helpers"; import { createConnection } from "coral-server/models/helpers"; import { getCommentEditableUntilDate } from "coral-server/services/comments"; @@ -68,7 +69,18 @@ export const Comment: GQLCommentTypeResolver = { c.childCount > 0 ? ctx.loaders.Comments.forParent(c.storyID, c.id, input) : createConnection(), - replyCount: ({ childCount }) => childCount || 0, + replyCount: async ({ childIDs }, input, ctx) => { + // TODO: (wyattjoh) the childCount should be used eventually, but it should be managed with the status so it's only a count of published comments + if (childIDs.length === 0) { + return 0; + } + + const children = await ctx.loaders.Comments.comment.loadMany(childIDs); + return children.reduce( + (sum, c) => (c && hasPublishedStatus(c) ? sum + 1 : sum), + 0 + ); + }, // Action Counts are encoded, decode them for use with the GraphQL system. actionCounts: c => decodeActionCounts(c.actionCounts), flags: ({ id }, { first = 10, after }, ctx) =>