mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2026-02-07 03:06:46 +00:00
feat: batch room meeting status queries into single bulk endpoint
Reduces rooms list page from 2N+2 HTTP requests to 1 POST request. Backend: POST /v1/rooms/meetings/bulk-status with 3 DB queries total. Frontend: @yornaath/batshit DataLoader-style batcher with 10ms window.
This commit is contained in:
25
www/app/lib/meetingStatusBatcher.ts
Normal file
25
www/app/lib/meetingStatusBatcher.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { create, keyResolver, windowScheduler } from "@yornaath/batshit";
|
||||
import { client } from "./apiClient";
|
||||
import type { components } from "../reflector-api";
|
||||
|
||||
type MeetingStatusResult = {
|
||||
roomName: string;
|
||||
active_meetings: components["schemas"]["Meeting"][];
|
||||
upcoming_events: components["schemas"]["CalendarEventResponse"][];
|
||||
};
|
||||
|
||||
export const meetingStatusBatcher = create({
|
||||
fetcher: async (roomNames: string[]): Promise<MeetingStatusResult[]> => {
|
||||
const unique = [...new Set(roomNames)];
|
||||
const { data } = await client.POST("/v1/rooms/meetings/bulk-status", {
|
||||
body: { room_names: unique },
|
||||
});
|
||||
return roomNames.map((name) => ({
|
||||
roomName: name,
|
||||
active_meetings: data?.[name]?.active_meetings ?? [],
|
||||
upcoming_events: data?.[name]?.upcoming_events ?? [],
|
||||
}));
|
||||
},
|
||||
resolver: keyResolver("roomName"),
|
||||
scheduler: windowScheduler(10),
|
||||
});
|
||||
Reference in New Issue
Block a user