Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(rethinkdb): Comment: Phase 1 #10166

Merged
merged 5 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
"mappers": {
"SetSlackNotificationPayload": "./types/SetSlackNotificationPayload#SetSlackNotificationPayloadSource",
"SetDefaultSlackChannelSuccess": "./types/SetDefaultSlackChannelSuccess#SetDefaultSlackChannelSuccessSource",
"AddCommentSuccess": "./types/AddCommentSuccess#AddCommentSuccessSource",
"DeleteCommentSuccess": "./types/DeleteCommentSuccess#DeleteCommentSuccessSource",
"UpdateCommentContentSuccess": "./types/UpdateCommentContentSuccess#UpdateCommentContentSuccessSource",
"AddSlackAuthPayload": "./types/AddSlackAuthPayload#AddSlackAuthPayloadSource",
"RemoveAgendaItemPayload": "./types/RemoveAgendaItemPayload#RemoveAgendaItemPayloadSource",
"AddAgendaItemPayload": "./types/AddAgendaItemPayload#AddAgendaItemPayloadSource",
Expand Down
4 changes: 2 additions & 2 deletions packages/client/components/DiscussionThreadInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ const DiscussionThreadInput = forwardRef((props: Props, ref: any) => {
isAnonymous: isAnonymousComment,
discussionId,
threadParentId,
threadSortOrder: getMaxSortOrder() + SORT_STEP + dndNoise()
threadSortOrder: getMaxSortOrder() + SORT_STEP
}
AddCommentMutation(atmosphere, {comment}, {onError, onCompleted})
// move focus to end is very important! otherwise ghost chars appear
Expand Down Expand Up @@ -263,7 +263,7 @@ const DiscussionThreadInput = forwardRef((props: Props, ref: any) => {
discussionId,
meetingId,
threadParentId,
threadSortOrder: getMaxSortOrder() + SORT_STEP + dndNoise(),
threadSortOrder: getMaxSortOrder() + SORT_STEP,
userId: viewerId,
teamId
} as const
Expand Down
13 changes: 13 additions & 0 deletions packages/embedder/workflows/helpers/publishSimilarRetroTopics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
buildCommentContentBlock,
createAIComment
} from '../../../server/graphql/mutations/helpers/addAIGeneratedContentToThreads'
import getKysely from '../../../server/postgres/getKysely'
import getPhase from '../../../server/utils/getPhase'
import publish from '../../../server/utils/publish'

Expand Down Expand Up @@ -54,6 +55,7 @@ export const publishSimilarRetroTopics = async (
dataLoader: DataLoaderInstance
) => {
const r = await getRethink()
const pg = getKysely()
const links = await Promise.all(
similarEmbeddings.map((se) => makeSimilarDiscussionLink(se, dataLoader))
)
Expand All @@ -68,5 +70,16 @@ export const publishSimilarRetroTopics = async (
2
)
await r.table('Comment').insert(relatedDiscussionsComment).run()
await pg
.insertInto('Comment')
.values({
id: relatedDiscussionsComment.id,
content: relatedDiscussionsComment.content,
plaintextContent: relatedDiscussionsComment.plaintextContent,
createdBy: relatedDiscussionsComment.createdBy,
threadSortOrder: relatedDiscussionsComment.threadSortOrder,
discussionId: relatedDiscussionsComment.discussionId
})
.execute()
publishComment(meetingId, relatedDiscussionsComment.id)
}
24 changes: 7 additions & 17 deletions packages/server/dataloader/customLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,31 +83,21 @@ export const commentCountByDiscussionId = (
dependsOn('comments')
return new DataLoader<string, number, string>(
async (discussionIds) => {
const r = await getRethink()
const groups = (await (
r
.table('Comment')
.getAll(r.args(discussionIds as string[]), {index: 'discussionId'})
.filter((row: RDatum) =>
row('isActive').eq(true).and(row('createdBy').ne(PARABOL_AI_USER_ID))
)
.group('discussionId') as any
const commentsByDiscussionId = await Promise.all(
discussionIds.map((discussionId) => parent.get('commentsByDiscussionId').load(discussionId))
)
.count()
.ungroup()
.run()) as {group: string; reduction: number}[]
const lookup: Record<string, number> = {}
groups.forEach(({group, reduction}) => {
lookup[group] = reduction
return commentsByDiscussionId.map((commentArr) => {
const activeHumanComments = commentArr.filter(
(comment) => comment.isActive && comment.createdBy !== PARABOL_AI_USER_ID
)
return activeHumanComments.length
})
return discussionIds.map((discussionId) => lookup[discussionId] || 0)
},
{
...parent.dataLoaderOptions
}
)
}

export const latestTaskEstimates = (parent: RootDataLoader) => {
return new DataLoader<string, IGetLatestTaskEstimatesQueryResult[], string>(
async (taskIds) => {
Expand Down
10 changes: 10 additions & 0 deletions packages/server/dataloader/foreignKeyLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import getKysely from '../postgres/getKysely'
import {getTeamPromptResponsesByMeetingIds} from '../postgres/queries/getTeamPromptResponsesByMeetingIds'
import {
selectAgendaItems,
selectComments,
selectOrganizations,
selectRetroReflections,
selectSlackAuths,
Expand Down Expand Up @@ -205,3 +206,12 @@ export const slackNotificationsByTeamId = foreignKeyLoaderMaker(
return selectSlackNotifications().where('teamId', 'in', teamIds).execute()
}
)

export const _pgcommentsByDiscussionId = foreignKeyLoaderMaker(
'_pgcomments',
'discussionId',
async (discussionIds) => {
// include deleted comments so we can replace them with tombstones
return selectComments().where('discussionId', 'in', discussionIds).execute()
}
)
5 changes: 5 additions & 0 deletions packages/server/dataloader/primaryKeyLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import getTemplateRefsByIds from '../postgres/queries/getTemplateRefsByIds'
import {getUsersByIds} from '../postgres/queries/getUsersByIds'
import {
selectAgendaItems,
selectComments,
selectMeetingSettings,
selectOrganizations,
selectRetroReflections,
Expand Down Expand Up @@ -105,3 +106,7 @@ export const slackAuths = primaryKeyLoaderMaker((ids: readonly string[]) => {
export const slackNotifications = primaryKeyLoaderMaker((ids: readonly string[]) => {
return selectSlackNotifications().where('id', 'in', ids).execute()
})

export const _pgcomments = primaryKeyLoaderMaker((ids: readonly string[]) => {
return selectComments().where('id', 'in', ids).execute()
})
183 changes: 0 additions & 183 deletions packages/server/graphql/mutations/addComment.ts

This file was deleted.

71 changes: 0 additions & 71 deletions packages/server/graphql/mutations/deleteComment.ts

This file was deleted.

Loading
Loading