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

fix: Crash when starting a checkin with agenda items #10383

Merged
merged 1 commit into from
Oct 21, 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
53 changes: 24 additions & 29 deletions packages/server/graphql/mutations/helpers/createNewMeetingPhases.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {InsertQueryBuilder} from 'kysely'
import {
AGENDA_ITEMS,
CHECKIN,
Expand All @@ -23,6 +24,7 @@ import UpdatesPhase from '../../../database/types/UpdatesPhase'
import UpdatesStage from '../../../database/types/UpdatesStage'
import {DataLoaderInstance} from '../../../dataloader/RootDataLoader'
import getKysely from '../../../postgres/getKysely'
import {DB} from '../../../postgres/pg'
import {MeetingTypeEnum} from '../../../postgres/types/Meeting'
import {NewMeetingPhase, NewMeetingStages} from '../../../postgres/types/NewMeetingPhase'
import isPhaseAvailable from '../../../utils/isPhaseAvailable'
Expand Down Expand Up @@ -84,7 +86,7 @@ const createNewMeetingPhases = async <T extends NewMeetingPhase = NewMeetingPhas
])
const {phaseTypes} = meetingSettings
const facilitatorTeamMemberId = toTeamMemberId(teamId, facilitatorUserId)
const asyncSideEffects = [] as Promise<any>[]
const inserts = [] as InsertQueryBuilder<DB, any, any>[]

const tier = getFeatureTier(team)
const phases = (await Promise.all(
Expand All @@ -109,19 +111,16 @@ const createNewMeetingPhases = async <T extends NewMeetingPhase = NewMeetingPhas
const discussPhase = new DiscussPhase(durations)
const discussStages = discussPhase.stages.filter((stage) => stage.reflectionGroupId)
if (discussStages.length > 0) {
asyncSideEffects.push(
pg
.insertInto('Discussion')
.values(
discussStages.map((stage) => ({
id: stage.discussionId,
teamId,
meetingId,
discussionTopicId: stage.reflectionGroupId,
discussionTopicType: 'reflectionGroup'
}))
)
.execute()
inserts.push(
pg.insertInto('Discussion').values(
discussStages.map((stage) => ({
id: stage.discussionId,
teamId,
meetingId,
discussionTopicId: stage.reflectionGroupId,
discussionTopicType: 'reflectionGroup'
}))
)
)
}
return discussPhase
Expand All @@ -133,19 +132,16 @@ const createNewMeetingPhases = async <T extends NewMeetingPhase = NewMeetingPhas
const agendaItemPhase = new AgendaItemsPhase(agendaItemIds, durations)
const {stages} = agendaItemPhase
if (stages.length > 0) {
asyncSideEffects.push(
pg
.insertInto('Discussion')
.values(
stages.map((stage) => ({
id: stage.discussionId,
teamId,
meetingId,
discussionTopicId: stage.agendaItemId,
discussionTopicType: 'agendaItem'
}))
)
.execute()
inserts.push(
pg.insertInto('Discussion').values(
stages.map((stage) => ({
id: stage.discussionId,
teamId,
meetingId,
discussionTopicId: stage.agendaItemId,
discussionTopicType: 'agendaItem'
}))
)
)
}
return agendaItemPhase
Expand All @@ -163,8 +159,7 @@ const createNewMeetingPhases = async <T extends NewMeetingPhase = NewMeetingPhas
})
)) as [T, ...T[]]
primePhases(phases)
await Promise.all(asyncSideEffects)
return phases
return [phases, inserts] as const
}

export default createNewMeetingPhases
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const safeCreateRetrospective = async (
const {showConversionModal} = organization

const meetingId = generateUID()
const phases = await createNewMeetingPhases<RetroMeetingPhase>(
const [phases, inserts] = await createNewMeetingPhases<RetroMeetingPhase>(
facilitatorUserId,
teamId,
meetingId,
Expand All @@ -51,10 +51,13 @@ const safeCreateRetrospective = async (
name
}) as RetrospectiveMeeting
try {
await pg
.insertInto('NewMeeting')
.values({...meeting, phases: JSON.stringify(meeting.phases)})
.execute()
await pg.transaction().execute(async (pg) => {
await pg
.insertInto('NewMeeting')
.values({...meeting, phases: JSON.stringify(meeting.phases)})
.execute()
await Promise.all(inserts.map((insert) => pg.executeQuery(insert)))
})
} catch (e) {
// meeting already started
return null
Expand Down
13 changes: 8 additions & 5 deletions packages/server/graphql/mutations/startSprintPoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default {
const meetingId = generateUID()
const meetingCount = await dataLoader.get('meetingCount').load({teamId, meetingType})

const phases = await createNewMeetingPhases<PokerMeetingPhase>(
const [phases, inserts] = await createNewMeetingPhases<PokerMeetingPhase>(
viewerId,
teamId,
meetingId,
Expand Down Expand Up @@ -145,10 +145,13 @@ export default {

const template = await dataLoader.get('meetingTemplates').load(selectedTemplateId)
const [newMeetingRes] = await Promise.allSettled([
pg
.insertInto('NewMeeting')
.values({...meeting, phases: JSON.stringify(phases)})
.execute(),
pg.transaction().execute(async (pg) => {
await pg
.insertInto('NewMeeting')
.values({...meeting, phases: JSON.stringify(phases)})
.execute()
await Promise.all(inserts.map((insert) => pg.executeQuery(insert)))
}),
updateMeetingTemplateLastUsedAt(selectedTemplateId, teamId)
])
if (newMeetingRes.status === 'rejected') {
Expand Down
13 changes: 8 additions & 5 deletions packages/server/graphql/public/mutations/startCheckIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const startCheckIn: MutationResolvers['startCheckIn'] = async (
const meetingCount = await dataLoader.get('meetingCount').load({teamId, meetingType})
const meetingId = generateUID()

const phases = await createNewMeetingPhases<CheckInPhase>(
const [phases, inserts] = await createNewMeetingPhases<CheckInPhase>(
viewerId,
teamId,
meetingId,
Expand All @@ -59,10 +59,13 @@ const startCheckIn: MutationResolvers['startCheckIn'] = async (
facilitatorUserId: viewerId
}) as CheckInMeeting
try {
await pg
.insertInto('NewMeeting')
.values({...meeting, phases: JSON.stringify(phases)})
.execute()
await pg.transaction().execute(async (pg) => {
await pg
.insertInto('NewMeeting')
.values({...meeting, phases: JSON.stringify(phases)})
.execute()
await Promise.all(inserts.map((insert) => pg.executeQuery(insert)))
})
} catch (e) {
return {error: {message: 'Meeting already started'}}
}
Expand Down
Loading