perf: batch user queries in schedules output service (#25901)
Replace N sequential queries with single batch query for fetching user default schedule IDs Changes: - Add getUsersScheduleDefaultIds batch method to UsersRepository - Add getResponseSchedules batch method to OutputSchedulesService - Extract transformScheduleToOutput for reuse - Simplify OrganizationsSchedulesService and TeamsSchedulesService - Remove dead code (formatInput no-op method) Reduces database round-trips from O(n) to O(1) for schedule lookups
This commit is contained in:
1 parent
69695d3022
commit
4226231b8a
4 files changed
+33
-39
No files matched your search
@@ -22,8 +22,6 @@ export class UsersRepository {
|
||||
oAuthClientId: string,
|
||||
isPlatformManaged: boolean
|
||||
) {
|
||||
this.formatInput(user);
|
||||
|
||||
return this.dbWrite.prisma.user.create({
|
||||
data: {
|
||||
...user,
|
||||
@@ -227,8 +225,6 @@ export class UsersRepository {
|
||||
}
|
||||
|
||||
async update(userId: number, updateData: UpdateManagedUserInput) {
|
||||
this.formatInput(updateData);
|
||||
|
||||
return this.dbWrite.prisma.user.update({
|
||||
where: { id: userId },
|
||||
data: updateData,
|
||||
@@ -257,12 +253,6 @@ export class UsersRepository {
|
||||
});
|
||||
}
|
||||
|
||||
formatInput(userInput: CreateManagedUserInput | UpdateManagedUserInput) {
|
||||
if (userInput.weekStart) {
|
||||
userInput.weekStart = userInput.weekStart;
|
||||
}
|
||||
}
|
||||
|
||||
setDefaultSchedule(userId: number, scheduleId: number) {
|
||||
return this.dbWrite.prisma.user.update({
|
||||
where: { id: userId },
|
||||
@@ -280,6 +270,14 @@ export class UsersRepository {
|
||||
return user?.defaultScheduleId;
|
||||
}
|
||||
|
||||
async getUsersScheduleDefaultIds(userIds: number[]): Promise<Map<number, number | null>> {
|
||||
const users = await this.dbRead.prisma.user.findMany({
|
||||
where: { id: { in: userIds } },
|
||||
select: { id: true, defaultScheduleId: true },
|
||||
});
|
||||
return new Map(users.map((user) => [user.id, user.defaultScheduleId]));
|
||||
}
|
||||
|
||||
async getOrganizationUsers(organizationId: number) {
|
||||
const profiles = await this.dbRead.prisma.profile.findMany({
|
||||
where: {
|
||||
|
||||
Reference in new issue
Block a user