Skip to content

Commit

Permalink
chore(rethinkdb): TaskHistory: One-shot (#10004)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Krick <[email protected]>
  • Loading branch information
mattkrick authored Jul 19, 2024
1 parent b0c2cf2 commit 7100a23
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 96 deletions.
4 changes: 0 additions & 4 deletions packages/server/database/rethinkDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ export type RethinkSchema = {
| 'userId'
| 'integrationHash'
}
TaskHistory: {
type: any
index: 'taskIdUpdatedAt' | 'teamMemberId'
}
TeamInvitation: {
type: TeamInvitation
index: 'email' | 'teamId' | 'token'
Expand Down
20 changes: 1 addition & 19 deletions packages/server/graphql/mutations/changeTaskTeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import {GraphQLID, GraphQLNonNull} from 'graphql'
import {SubscriptionChannel} from 'parabol-client/types/constEnums'
import removeEntityKeepText from 'parabol-client/utils/draftjs/removeEntityKeepText'
import getRethink from '../../database/rethinkDriver'
import {RValue} from '../../database/stricterR'
import Task from '../../database/types/Task'
import generateUID from '../../generateUID'
import {AtlassianAuth} from '../../postgres/queries/getAtlassianAuthByUserIdTeamId'
import {GitHubAuth} from '../../postgres/queries/getGitHubAuthByUserIdTeamId'
import upsertAtlassianAuths from '../../postgres/queries/upsertAtlassianAuths'
Expand Down Expand Up @@ -155,23 +153,7 @@ export default {
.filter({teamId})
.delete({returnChanges: true})('changes')(0)('old_val')
.default(null),
newTask: r.table('Task').get(taskId).update(updates),
taskHistory: r
.table('TaskHistory')
.between([taskId, r.minval], [taskId, r.maxval], {
index: 'taskIdUpdatedAt'
})
.orderBy({index: 'taskIdUpdatedAt'})
.nth(-1)
.default(null)
.do((taskHistoryRecord: RValue) => {
// prepopulated cards will not have a history
return r.branch(
taskHistoryRecord.ne(null),
r.table('TaskHistory').insert(taskHistoryRecord.merge(updates, {id: generateUID()})),
null
)
})
newTask: r.table('Task').get(taskId).update(updates)
}).run()

if (deletedConflictingIntegrationTask) {
Expand Down
15 changes: 2 additions & 13 deletions packages/server/graphql/mutations/createTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import MeetingMemberId from '../../../client/shared/gqlIds/MeetingMemberId'
import getRethink from '../../database/rethinkDriver'
import NotificationTaskInvolves from '../../database/types/NotificationTaskInvolves'
import Task, {TaskServiceEnum} from '../../database/types/Task'
import generateUID from '../../generateUID'
import updatePrevUsedRepoIntegrationsCache from '../../integrations/updatePrevUsedRepoIntegrationsCache'
import {analytics} from '../../utils/analytics/analytics'
import {getUserId, isTeamMember} from '../../utils/authorization'
Expand Down Expand Up @@ -218,20 +217,10 @@ export default {
threadParentId,
userId
})
const {id: taskId, updatedAt} = task
const history = {
id: generateUID(),
content,
taskId,
status,
teamId,
userId,
updatedAt
}
const {id: taskId} = task
const teamMembers = await dataLoader.get('teamMembersByTeamId').load(teamId)
await r({
task: r.table('Task').insert(task),
history: r.table('TaskHistory').insert(history)
task: r.table('Task').insert(task)
}).run()

handleAddTaskNotifications(teamMembers, task, viewerId, teamId, {
Expand Down
8 changes: 1 addition & 7 deletions packages/server/graphql/mutations/deleteTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@ export default {
const teamMembers = await dataLoader.get('teamMembersByTeamId').load(teamId)
const subscribedUserIds = teamMembers.map(({userId}) => userId)
await r({
task: r.table('Task').get(taskId).delete(),
taskHistory: r
.table('TaskHistory')
.between([taskId, r.minval], [taskId, r.maxval], {
index: 'taskIdUpdatedAt'
})
.delete()
task: r.table('Task').get(taskId).delete()
}).run()
const {tags, userId: taskUserId} = task

Expand Down
19 changes: 1 addition & 18 deletions packages/server/graphql/mutations/helpers/addSeedTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import getTagsFromEntityMap from 'parabol-client/utils/draftjs/getTagsFromEntity
import makeAppURL from 'parabol-client/utils/makeAppURL'
import appOrigin from '../../../appOrigin'
import getRethink from '../../../database/rethinkDriver'
import {RValue} from '../../../database/stricterR'
import {TaskStatusEnum} from '../../../database/types/Task'
import generateUID from '../../../generateUID'
import {convertHtmlToTaskContent} from '../../../utils/draftjs/convertHtmlToTaskContent'
Expand Down Expand Up @@ -52,21 +51,5 @@ export default async (userId: string, teamId: string) => {
updatedAt: now
}))

return r
.table('Task')
.insert(seedTasks, {returnChanges: true})
.do((result: RValue) => {
return r.table('TaskHistory').insert(
result('changes').map((change: RValue) => ({
id: generateUID(),
content: change('new_val')('content'),
taskId: change('new_val')('id'),
status: change('new_val')('status'),
teamId: change('new_val')('teamId'),
userId: change('new_val')('userId'),
updatedAt: change('new_val')('updatedAt')
}))
)
})
.run()
return r.table('Task').insert(seedTasks).run()
}
36 changes: 1 addition & 35 deletions packages/server/graphql/mutations/updateTask.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import {GraphQLNonNull, GraphQLObjectType} from 'graphql'
import ms from 'ms'
import {SubscriptionChannel} from 'parabol-client/types/constEnums'
import extractTextFromDraftString from 'parabol-client/utils/draftjs/extractTextFromDraftString'
import normalizeRawDraftJS from 'parabol-client/validation/normalizeRawDraftJS'
import getRethink from '../../database/rethinkDriver'
import {RValue} from '../../database/stricterR'
import Task, {AreaEnum as TAreaEnum, TaskStatusEnum} from '../../database/types/Task'
import generateUID from '../../generateUID'
import {getUserId, isTeamMember} from '../../utils/authorization'
import publish from '../../utils/publish'
import standardError from '../../utils/standardError'
Expand All @@ -17,8 +14,6 @@ import {validateTaskUserIsTeamMember} from './createTask'
import getUsersToIgnore from './helpers/getUsersToIgnore'
import publishChangeNotifications from './helpers/publishChangeNotifications'

const DEBOUNCE_TIME = ms('5m')

type UpdateTaskInput = {
id: string
content?: string | null
Expand Down Expand Up @@ -91,42 +86,13 @@ export default {
updatedAt: isSortOrderUpdate ? task.updatedAt : now
})

let taskHistory
if (!isSortOrderUpdate) {
// if this is anything but a sort update, log it to history
const mergeDoc = {
content: nextTask.content,
taskId,
status,
userId: nextTask.userId,
teamId: nextTask.teamId,
updatedAt: now,
tags: nextTask.tags
}
taskHistory = r
.table('TaskHistory')
.between([taskId, r.minval], [taskId, r.maxval], {
index: 'taskIdUpdatedAt'
})
.orderBy({index: 'taskIdUpdatedAt'})
.nth(-1)
.default({updatedAt: r.epochTime(0)})
.do((lastDoc: RValue) => {
return r.branch(
lastDoc('updatedAt').gt(r.epochTime((now.getTime() - DEBOUNCE_TIME) / 1000)),
r.table('TaskHistory').get(lastDoc('id')).update(mergeDoc),
r.table('TaskHistory').insert(lastDoc.merge(mergeDoc, {id: generateUID()}))
)
})
}
const teamMembers = await dataLoader.get('teamMembersByTeamId').load(teamId)
const {newTask} = await r({
newTask: r
.table('Task')
.get(taskId)
.update(nextTask, {returnChanges: true})('changes')(0)('new_val')
.default(null) as unknown as Task,
history: taskHistory
.default(null) as unknown as Task
}).run()
// TODO: get users in the same location
const usersToIgnore = await getUsersToIgnore(viewerId, teamId)
Expand Down

0 comments on commit 7100a23

Please sign in to comment.