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: latestMeeting query #10429

Merged
merged 2 commits into from
Oct 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
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
Loading