feat(messages): stream history one-message-per-WS-frame instead of 50-row batch
- backend: add streamMany generator (paginated, yields one record at a time) + messagesService.streamMessages + WS 'stream_messages' handler emitting 'message_snapshot' per message, 'message_snapshot_end' with nextCursor - frontend: useMessagesStream hook accumulates snapshots into SWR list, SSR getMessages seeds first paint, WsHook gains sendText - add stream-many.test.ts locking the one-at-a-time + cursor contract
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { PageTransition } from "@/components/shared";
|
||||
import { getConfig, getGuilds } from "@/lib/api/server";
|
||||
import { getConfig, getGuilds, getMessages } from "@/lib/api/server";
|
||||
import { MessagesView } from "./view";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
@@ -7,8 +7,16 @@ export const dynamic = "force-dynamic";
|
||||
export default async function MessagesPage() {
|
||||
let config: import("@/lib/types/guild").AppConfig | undefined;
|
||||
let guilds: import("@/lib/types").Guild[] | undefined;
|
||||
let initialMessages: {
|
||||
data: import("@/lib/types").MessageRecord[];
|
||||
nextCursor: string | null;
|
||||
} | null = null;
|
||||
try {
|
||||
[config, guilds] = await Promise.all([getConfig(), getGuilds()]);
|
||||
const gid = config?.monitorGuildId;
|
||||
if (gid) {
|
||||
initialMessages = await getMessages(gid, undefined, 50);
|
||||
}
|
||||
} catch {
|
||||
/* client hooks surface errors */
|
||||
}
|
||||
@@ -17,6 +25,7 @@ export default async function MessagesPage() {
|
||||
<MessagesView
|
||||
initialGuilds={guilds}
|
||||
initialGuildId={config?.monitorGuildId ?? null}
|
||||
initialMessages={initialMessages}
|
||||
/>
|
||||
</PageTransition>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user