From 8abbb483fc050835da931d7e06e957dfb19d2c00 Mon Sep 17 00:00:00 2001 From: nick-funk Date: Fri, 24 Nov 2023 13:03:45 -0700 Subject: [PATCH 1/2] don't use data cache for retrieving R&R, QA, archived action presence we don't prime the cache when we have stories in these states, so we can't rely on the cache for this data. Instead, rely on mongo for these isolated incidents and the action presence will be correct. --- server/src/core/server/graph/loaders/Comments.ts | 8 ++++++-- server/src/core/server/graph/resolvers/Comment.ts | 3 +++ server/src/core/server/models/action/comment.ts | 4 +++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/server/src/core/server/graph/loaders/Comments.ts b/server/src/core/server/graph/loaders/Comments.ts index 66e743aba8..003471e8b5 100644 --- a/server/src/core/server/graph/loaders/Comments.ts +++ b/server/src/core/server/graph/loaders/Comments.ts @@ -58,7 +58,7 @@ const tagFilter = (tag?: GQLTAG): CommentConnectionInput["filter"] => { return {}; }; -const isRatingsAndReviews = ( +export const isRatingsAndReviews = ( tenant: Pick, story: Story ) => { @@ -68,7 +68,7 @@ const isRatingsAndReviews = ( ); }; -const isQA = (tenant: Pick, story: Story) => { +export const isQA = (tenant: Pick, story: Story) => { return ( hasFeatureFlag(tenant, GQLFEATURE_FLAG.ENABLE_QA) && story.settings.mode === GQLSTORY_MODE.QA @@ -173,6 +173,8 @@ const mapVisibleComment = (user?: Pick) => { interface ActionPresenceArgs { commentID: string; isArchived: boolean; + isQA: boolean; + isRR: boolean; } /** @@ -268,6 +270,7 @@ export default (ctx: GraphContext) => ({ const commentIDs = args.map((rd) => rd.commentID); const hasArchivedData = args.some((rd) => rd.isArchived); + const hasRROrQA = args.some((rd) => rd.isQA || rd.isRR); const result = await retrieveManyUserActionPresence( ctx.mongo, @@ -275,6 +278,7 @@ export default (ctx: GraphContext) => ({ ctx.tenant.id, ctx.user.id, commentIDs, + !(hasRROrQA || hasArchivedData), hasArchivedData ); diff --git a/server/src/core/server/graph/resolvers/Comment.ts b/server/src/core/server/graph/resolvers/Comment.ts index 8abf05999c..1f0143c6fc 100644 --- a/server/src/core/server/graph/resolvers/Comment.ts +++ b/server/src/core/server/graph/resolvers/Comment.ts @@ -32,6 +32,7 @@ import { } from "coral-server/graph/schema/__generated__/types"; import GraphContext from "../context"; +import { isQA, isRatingsAndReviews } from "../loaders/Comments"; import { setCacheHint } from "../setCacheHint"; export const maybeLoadOnlyID = async ( @@ -213,6 +214,8 @@ export const Comment: GQLCommentTypeResolver = { return ctx.loaders.Comments.retrieveMyActionPresence.load({ commentID: c.id, isArchived: !!story.isArchived, + isRR: isRatingsAndReviews(ctx.tenant, story), + isQA: isQA(ctx.tenant, story), }); }, diff --git a/server/src/core/server/models/action/comment.ts b/server/src/core/server/models/action/comment.ts index df520c2693..af2380b711 100644 --- a/server/src/core/server/models/action/comment.ts +++ b/server/src/core/server/models/action/comment.ts @@ -377,11 +377,13 @@ export async function retrieveManyUserActionPresence( tenantID: string, userID: string | null, commentIDs: string[], + useCache = true, isArchived = false ): Promise { let actions: Readonly[] = []; - const cacheAvailable = await commentActionsCache.available(tenantID); + const cacheAvailable = + useCache && (await commentActionsCache.available(tenantID)); if (cacheAvailable) { const actionsFromCache = await commentActionsCache.findMany( tenantID, From cfaa294dee3b103b5ff2b6d68f6263a946ff72bf Mon Sep 17 00:00:00 2001 From: nick-funk Date: Fri, 24 Nov 2023 13:04:34 -0700 Subject: [PATCH 2/2] allow admins to archive/unarchive stories --- client/src/core/client/admin/permissions/story.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/core/client/admin/permissions/story.ts b/client/src/core/client/admin/permissions/story.ts index 49e0273588..973492a6e7 100644 --- a/client/src/core/client/admin/permissions/story.ts +++ b/client/src/core/client/admin/permissions/story.ts @@ -17,7 +17,7 @@ const permissionMap: PermissionMap = { [GQLUSER_ROLE.MODERATOR]: () => true, }, ARCHIVE_STORY: { - [GQLUSER_ROLE.ADMIN]: () => false, + [GQLUSER_ROLE.ADMIN]: () => true, }, };