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 3 #10172

Merged
merged 8 commits into from
Sep 9, 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
2 changes: 1 addition & 1 deletion codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"AzureDevOpsRemoteProject": "./types/AzureDevOpsRemoteProject#AzureDevOpsRemoteProjectSource",
"AzureDevOpsWorkItem": "../../dataloader/azureDevOpsLoaders#AzureDevOpsWorkItem",
"BatchArchiveTasksSuccess": "./types/BatchArchiveTasksSuccess#BatchArchiveTasksSuccessSource",
"Comment": "../../database/types/Comment#default as CommentDB",
"Comment": "../../postgres/types/index#Comment as CommentDB",
"Company": "./types/Company#CompanySource",
"CreateGcalEventInput": "./types/CreateGcalEventInput#default",
"CreateImposterTokenPayload": "./types/CreateImposterTokenPayload#CreateImposterTokenPayloadSource",
Expand Down
4 changes: 2 additions & 2 deletions packages/embedder/indexing/retrospectiveDiscussionTopic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Comment from 'parabol-server/database/types/Comment'
import {isMeetingRetrospective} from 'parabol-server/database/types/MeetingRetrospective'
import {DataLoaderInstance} from 'parabol-server/dataloader/RootDataLoader'
import prettier from 'prettier'
import {Comment} from '../../server/postgres/types'
import {inferLanguage} from '../inferLanguage'
import {ISO6391} from '../iso6393To1'

Expand Down Expand Up @@ -154,7 +154,7 @@ export const createTextFromRetrospectiveDiscussionTopic = async (
}) as Comment[]

const filteredComments = sortedComments.filter(
(c) => !IGNORE_COMMENT_USER_IDS.includes(c.createdBy)
(c) => !IGNORE_COMMENT_USER_IDS.includes(c.createdBy!)
)
if (filteredComments.length) {
markdown += `Further discussion was made:\n`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {SubscriptionChannel} from '../../../client/types/constEnums'
import makeAppURL from '../../../client/utils/makeAppURL'
import appOrigin from '../../../server/appOrigin'
import getRethink from '../../../server/database/rethinkDriver'
import {DataLoaderInstance} from '../../../server/dataloader/RootDataLoader'
import {isRetroMeeting} from '../../../server/graphql/meetingTypePredicates'
import {
Expand Down Expand Up @@ -54,7 +53,6 @@ export const publishSimilarRetroTopics = async (
similarEmbeddings: {embeddingsMetadataId: number; similarity: number}[],
dataLoader: DataLoaderInstance
) => {
const r = await getRethink()
const pg = getKysely()
const links = await Promise.all(
similarEmbeddings.map((se) => makeSimilarDiscussionLink(se, dataLoader))
Expand All @@ -69,7 +67,6 @@ export const publishSimilarRetroTopics = async (
buildCommentContentBlock('🤖 Related Discussions', `<ul>${listItems}</ul>`),
2
)
await r.table('Comment').insert(relatedDiscussionsComment).run()
await pg
.insertInto('Comment')
.values({
Expand Down
5 changes: 0 additions & 5 deletions packages/server/database/rethinkDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import TeamInvitation from '../database/types/TeamInvitation'
import {AnyMeeting, AnyMeetingTeamMember} from '../postgres/types/Meeting'
import getRethinkConfig from './getRethinkConfig'
import {R} from './stricterR'
import Comment from './types/Comment'
import MassInvitation from './types/MassInvitation'
import NotificationKickedOut from './types/NotificationKickedOut'
import NotificationMeetingStageTimeLimitEnd from './types/NotificationMeetingStageTimeLimitEnd'
Expand All @@ -21,10 +20,6 @@ import RetrospectivePrompt from './types/RetrospectivePrompt'
import Task from './types/Task'

export type RethinkSchema = {
Comment: {
type: Comment
index: 'discussionId'
}
ReflectPrompt: {
type: RetrospectivePrompt
index: 'teamId' | 'templateId'
Expand Down
63 changes: 0 additions & 63 deletions packages/server/database/types/Comment.ts

This file was deleted.

15 changes: 0 additions & 15 deletions packages/server/database/types/Reactji.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/server/dataloader/foreignKeyLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ export const slackNotificationsByTeamId = foreignKeyLoaderMaker(
}
)

export const _pgcommentsByDiscussionId = foreignKeyLoaderMaker(
'_pgcomments',
export const commentsByDiscussionId = foreignKeyLoaderMaker(
'comments',
'discussionId',
async (discussionIds) => {
// include deleted comments so we can replace them with tombstones
Expand Down
2 changes: 1 addition & 1 deletion packages/server/dataloader/primaryKeyLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ export const slackNotifications = primaryKeyLoaderMaker((ids: readonly string[])
return selectSlackNotifications().where('id', 'in', ids).execute()
})

export const _pgcomments = primaryKeyLoaderMaker((ids: readonly string[]) => {
export const comments = primaryKeyLoaderMaker((ids: readonly string[]) => {
return selectComments().where('id', 'in', ids).execute()
})
17 changes: 0 additions & 17 deletions packages/server/dataloader/rethinkForeignKeyLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,6 @@ export const activeMeetingsByTeamId = new RethinkForeignKeyLoaderMaker(
.run()
}
)

export const commentsByDiscussionId = new RethinkForeignKeyLoaderMaker(
'comments',
'discussionId',
async (discussionIds) => {
const r = await getRethink()
return (
r
.table('Comment')
.getAll(r.args(discussionIds), {index: 'discussionId'})
// include deleted comments so we can replace them with tombstones
// .filter({isActive: true})
.run()
)
}
)

export const completedMeetingsByTeamId = new RethinkForeignKeyLoaderMaker(
'newMeetings',
'teamId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import RethinkPrimaryKeyLoaderMaker from './RethinkPrimaryKeyLoaderMaker'
/**
* all rethink dataloader types which also must exist in {@link rethinkDriver/RethinkSchema}
*/
export const comments = new RethinkPrimaryKeyLoaderMaker('Comment')
export const reflectPrompts = new RethinkPrimaryKeyLoaderMaker('ReflectPrompt')
export const massInvitations = new RethinkPrimaryKeyLoaderMaker('MassInvitation')
export const meetingMembers = new RethinkPrimaryKeyLoaderMaker('MeetingMember')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {Insertable} from 'kysely'
import {PARABOL_AI_USER_ID} from '../../../../client/utils/constants'
import getRethink from '../../../database/rethinkDriver'
import Comment from '../../../database/types/Comment'
import extractTextFromDraftString from '../../../../client/utils/draftjs/extractTextFromDraftString'
import DiscussStage from '../../../database/types/DiscussStage'
import generateUID from '../../../generateUID'
import getKysely from '../../../postgres/getKysely'
import {Comment} from '../../../postgres/pg'
import {convertHtmlToTaskContent} from '../../../utils/draftjs/convertHtmlToTaskContent'
import {DataLoaderWorker} from '../../graphql'

Expand All @@ -16,27 +18,25 @@ export const buildCommentContentBlock = (
return convertHtmlToTaskContent(html)
}

export const createAIComment = (discussionId: string, content: string, order: number) =>
new Comment({
discussionId,
content,
threadSortOrder: order,
createdBy: PARABOL_AI_USER_ID
})
export const createAIComment = (discussionId: string, content: string, order: number) => ({
id: generateUID(),
discussionId,
content,
plaintextContent: extractTextFromDraftString(content),
threadSortOrder: order,
createdBy: PARABOL_AI_USER_ID
})

const addAIGeneratedContentToThreads = async (
stages: DiscussStage[],
meetingId: string,
dataLoader: DataLoaderWorker
) => {
const [r, groups] = await Promise.all([
getRethink(),
dataLoader.get('retroReflectionGroupsByMeetingId').load(meetingId)
])
const groups = await dataLoader.get('retroReflectionGroupsByMeetingId').load(meetingId)
const commentPromises = stages.map(async ({discussionId, reflectionGroupId}) => {
const group = groups.find((group) => group.id === reflectionGroupId)
if (!group?.discussionPromptQuestion) return
const comments: Comment[] = []
const comments: Insertable<Comment>[] = []

if (group.discussionPromptQuestion) {
const topicSummaryComment = createAIComment(
Expand All @@ -46,16 +46,7 @@ const addAIGeneratedContentToThreads = async (
)
comments.push(topicSummaryComment)
}
const pgComments = comments.map((comment) => ({
id: comment.id,
content: comment.content,
plaintextContent: comment.plaintextContent,
createdBy: comment.createdBy,
threadSortOrder: comment.threadSortOrder,
discussionId: comment.discussionId
}))
await getKysely().insertInto('Comment').values(pgComments).execute()
return r.table('Comment').insert(comments).run()
await getKysely().insertInto('Comment').values(comments).execute()
})
await Promise.all(commentPromises)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const calculateEngagement = async (meeting: Meeting, dataLoader: DataLoaderWorke
])
const threadables = [...discussions.flat(), ...tasks.flat()]
threadables.forEach(({createdBy}) => {
passiveMembers.delete(createdBy)
createdBy && passiveMembers.delete(createdBy)
})

discussions.forEach((comments) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ const getSlackMessageForNotification = async (
return null
}
const author = await dataLoader.get('users').loadNonNull(notification.authorId)
const comment = await dataLoader.get('comments').load(notification.commentId)
const comment = await dataLoader.get('comments').loadNonNull(notification.commentId)

const authorName = comment.isAnonymous ? 'Anonymous' : author.preferredName

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ const resetRetroMeetingToGroupStage = {
reflectionGroups.forEach((rg) => (rg.voterIds = []))

await Promise.all([
r
.table('Comment')
.getAll(r.args(discussionIdsToDelete), {index: 'discussionId'})
.delete()
.run(),
pg.deleteFrom('Comment').where('discussionId', 'in', discussionIdsToDelete).execute(),
r.table('Task').getAll(r.args(discussionIdsToDelete), {index: 'discussionId'}).delete().run(),
pg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ const generateMeetingSummary: MutationResolvers['generateMeetingSummary'] = asyn
if (!discussion) return null
const {id: discussionId} = discussion
const rawComments = await dataLoader.get('commentsByDiscussionId').load(discussionId)
const humanComments = rawComments.filter((c) => !IGNORE_COMMENT_USER_IDS.includes(c.createdBy))
const humanComments = rawComments.filter((c) => !IGNORE_COMMENT_USER_IDS.includes(c.createdBy!))
const rootComments = humanComments.filter((c) => !c.threadParentId)
rootComments.sort((a, b) => {
return a.createdAt.getTime() < b.createdAt.getTime() ? -1 : 1
})
const comments = await Promise.all(
rootComments.map(async (comment) => {
const {createdBy, isAnonymous, plaintextContent} = comment
const creator = await dataLoader.get('users').loadNonNull(createdBy)
const commentAuthor = isAnonymous ? 'Anonymous' : creator.preferredName
const creator = createdBy ? await dataLoader.get('users').loadNonNull(createdBy) : null
const commentAuthor = isAnonymous || !creator ? 'Anonymous' : creator.preferredName
const commentReplies = await Promise.all(
humanComments
.filter((c) => c.threadParentId === comment.id)
Expand All @@ -63,8 +63,10 @@ const generateMeetingSummary: MutationResolvers['generateMeetingSummary'] = asyn
})
.map(async (reply) => {
const {createdBy, isAnonymous, plaintextContent} = reply
const creator = await dataLoader.get('users').loadNonNull(createdBy)
const replyAuthor = isAnonymous ? 'Anonymous' : creator.preferredName
const creator = createdBy
? await dataLoader.get('users').loadNonNull(createdBy)
: null
const replyAuthor = isAnonymous || !creator ? 'Anonymous' : creator.preferredName
return {
text: plaintextContent,
author: replyAuthor
Expand Down
12 changes: 2 additions & 10 deletions packages/server/graphql/private/mutations/hardDeleteUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const hardDeleteUser: MutationResolvers['hardDeleteUser'] = async (
const teamDiscussionIds = discussions.rows.map(({id}) => id)

// soft delete first for side effects
const tombstoneId = await softDeleteUser(userIdToDelete, dataLoader)
await softDeleteUser(userIdToDelete, dataLoader)

// all other writes
await setFacilitatedUserIdOrDelete(userIdToDelete, teamIds, dataLoader)
Expand Down Expand Up @@ -103,15 +103,7 @@ const hardDeleteUser: MutationResolvers['hardDeleteUser'] = async (
.table('TeamInvitation')
.getAll(r.args(teamIds), {index: 'teamId'})
.filter((row: RValue) => row('acceptedBy').eq(userIdToDelete))
.update({acceptedBy: ''}),
comment: r
.table('Comment')
.getAll(r.args(teamDiscussionIds), {index: 'discussionId'})
.filter((row: RValue) => row('createdBy').eq(userIdToDelete))
.update({
createdBy: tombstoneId,
isAnonymous: true
})
.update({acceptedBy: ''})
}).run()

// now postgres, after FKs are added then triggers should take care of children
Expand Down
Loading
Loading