feat: Update how messages load and sync, allow plugins to import messages
All checks were successful
Queue Release Build / prepare (push) Successful in 23s
Deploy Web Apps / deploy (push) Successful in 7m36s
Queue Release Build / build-windows (push) Successful in 28m3s
Queue Release Build / build-linux (push) Successful in 44m14s
Queue Release Build / finalize (push) Successful in 39s
All checks were successful
Queue Release Build / prepare (push) Successful in 23s
Deploy Web Apps / deploy (push) Successful in 7m36s
Queue Release Build / build-windows (push) Successful in 28m3s
Queue Release Build / build-linux (push) Successful in 44m14s
Queue Release Build / finalize (push) Successful in 39s
This commit is contained in:
@@ -289,6 +289,12 @@ async function processSyncBatch(
|
||||
attachments: AttachmentFacade
|
||||
): Promise<Message[]> {
|
||||
const toUpsert: Message[] = [];
|
||||
// Yield to the event loop every YIELD_EVERY messages so Angular change
|
||||
// detection and user input aren't starved while a large sync batch
|
||||
// (e.g. from a bulk plugin import) drains serial DB writes.
|
||||
const YIELD_EVERY = 50;
|
||||
|
||||
let processed = 0;
|
||||
|
||||
for (const incoming of event.messages) {
|
||||
attachments.rememberMessageRoom(incoming.id, incoming.roomId);
|
||||
@@ -305,6 +311,12 @@ async function processSyncBatch(
|
||||
|
||||
if (changed)
|
||||
toUpsert.push(message);
|
||||
|
||||
processed += 1;
|
||||
|
||||
if (processed % YIELD_EVERY === 0) {
|
||||
await new Promise<void>((resolve) => setTimeout(resolve, 0));
|
||||
}
|
||||
}
|
||||
|
||||
if (hasAttachmentMetaMap(event.attachments)) {
|
||||
@@ -603,13 +615,20 @@ function handleSyncRequest(
|
||||
return from(
|
||||
(async () => {
|
||||
const all = await db.getMessages(targetRoomId, FULL_SYNC_LIMIT, 0);
|
||||
const syncFullEvent: ChatEvent = {
|
||||
type: 'chat-sync-full',
|
||||
roomId: targetRoomId,
|
||||
messages: all
|
||||
};
|
||||
|
||||
webrtc.sendToPeer(fromPeerId, syncFullEvent);
|
||||
// Ship as chunked chat-sync-batch events instead of a single
|
||||
// chat-sync-full payload. A monolithic dump of up to FULL_SYNC_LIMIT
|
||||
// messages can exceed the WebRTC SCTP per-message size ceiling and be
|
||||
// silently dropped - especially after bulk plugin imports.
|
||||
for (const chunk of chunkArray(all, CHUNK_SIZE)) {
|
||||
const syncBatchEvent: ChatEvent = {
|
||||
type: 'chat-sync-batch',
|
||||
roomId: targetRoomId,
|
||||
messages: chunk
|
||||
};
|
||||
|
||||
webrtc.sendToPeer(fromPeerId, syncBatchEvent);
|
||||
}
|
||||
})()
|
||||
).pipe(mergeMap(() => EMPTY));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user