Skip to content

Commit

Permalink
fix: latestMeeting query (#10429)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Krick <matt.krick@gmail.com>
  • Loading branch information
mattkrick authored Oct 29, 2024
1 parent 27ff2dc commit 1b36b18
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
34 changes: 24 additions & 10 deletions packages/server/dataloader/customLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Selectable, SqlBool, sql} from 'kysely'
import {PARABOL_AI_USER_ID} from '../../client/utils/constants'
import MeetingTemplate from '../database/types/MeetingTemplate'
import getFileStoreManager from '../fileStorage/getFileStoreManager'
import isValid from '../graphql/isValid'
import {ReactableEnum} from '../graphql/public/resolverTypes'
import {SAMLSource} from '../graphql/public/types/SAML'
import getKysely from '../postgres/getKysely'
Expand Down Expand Up @@ -35,6 +36,7 @@ import isUserVerified from '../utils/isUserVerified'
import NullableDataLoader from './NullableDataLoader'
import RootDataLoader, {RegisterDependsOn} from './RootDataLoader'
import normalizeArrayResults from './normalizeArrayResults'
import normalizeResults from './normalizeResults'
export interface MeetingSettingsKey {
teamId: string
meetingType: MeetingTypeEnum
Expand Down Expand Up @@ -584,16 +586,28 @@ export const lastMeetingByMeetingSeriesId = (
dependsOn('newMeetings')
return new DataLoader<number, AnyMeeting | null, string>(
async (keys) => {
return await Promise.all(
keys.map(async (key) => {
const latestMeeting = await selectNewMeetings()
.where('meetingSeriesId', '=', key)
.orderBy('createdAt desc')
.limit(1)
.executeTakeFirst()
return latestMeeting || null
})
)
const meetingIdRes = await getKysely()
.with('LastMeetings', (qc) =>
qc
.selectFrom('NewMeeting')
.select([
'id',
'meetingSeriesId',
'createdAt',
sql`ROW_NUMBER() OVER (PARTITION BY "meetingSeriesId" ORDER BY "createdAt" DESC)`.as(
'rn'
)
])
.where('meetingSeriesId', 'in', keys)
)
.selectFrom('LastMeetings')
.select('id')
.where('rn', '=', 1)
.execute()

const meetingIds = meetingIdRes.map(({id}) => id)
const meetings = (await parent.get('newMeetings').loadMany(meetingIds)).filter(isValid)
return normalizeResults(keys, meetings, 'meetingSeriesId')
},
{
...parent.dataLoaderOptions
Expand Down
14 changes: 2 additions & 12 deletions packages/server/postgres/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {JSONContent} from '@tiptap/core'
import {NotNull, sql} from 'kysely'
import {NewMeetingPhaseTypeEnum} from '../graphql/public/resolverTypes'
import getKysely from './getKysely'
import {ReactjiDB, TaskTag} from './types'
import {JiraDimensionField, ReactjiDB, TaskTag} from './types'
import {AnyMeeting, AnyMeetingMember} from './types/Meeting'
import {AnyNotification} from './types/Notification'
import {AnyTaskIntegration} from './types/TaskIntegration'
Expand Down Expand Up @@ -90,17 +90,7 @@ export const selectTeams = () =>
'updatedAt'
])
.select(({fn}) => [
fn<
{
dimensionName: string
cloudId: string
projectKey: string
issueKey: string
fieldName: string
fieldType: string
fieldId: string
}[]
>('to_json', ['jiraDimensionFields']).as('jiraDimensionFields')
fn<JiraDimensionField[]>('to_json', ['jiraDimensionFields']).as('jiraDimensionFields')
])

export const selectRetroReflections = () =>
Expand Down
10 changes: 10 additions & 0 deletions packages/server/postgres/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ type ExtractTypeFromQueryBuilderSelect<T extends (...args: any[]) => any> =
export type Discussion = Selectable<DiscussionPG>
export type ReactjiDB = {id: string; userId: string}

export type JiraDimensionField = {
dimensionName: string
cloudId: string
projectKey: string
issueKey: string
fieldName: string
fieldType: string
fieldId: string
}

export type UsedReactjis = Record<string, number>
export type TranscriptBlock = {
speaker: string
Expand Down

0 comments on commit 1b36b18

Please sign in to comment.