Files
outline/server/queues/processors/DocumentStateProcessor.ts
Tom Moor d29bd1c788 feat: Flatten collaborative state of large documents
Replace edit history in large collaborative state with fresh state once a
document is idle with no open sessions, and when state is over the maximum
length on save. Each replacement increments a state generation that is part of
the collaboration room name, so old state never merges into the new state.
2026-11-13 22:52:37 -05:00

27 lines
868 B
TypeScript

import documentStateFlattener from "@server/commands/documentStateFlattener";
import type { DocumentEvent, Event } from "@server/types";
import BaseProcessor from "./BaseProcessor";
export default class DocumentStateProcessor extends BaseProcessor {
static applicableEvents: Event["name"][] = ["documents.update.debounced"];
/**
* Flatten the collaborative state of a document once nobody has edited it
* for some time, so that users are unlikely to see the reset.
*
* @param event the debounced update event.
* @returns a promise resolving when the event is processed.
*/
async perform(event: DocumentEvent) {
if (event.name !== "documents.update.debounced") {
return;
}
await documentStateFlattener({
documentId: event.documentId,
actorId: event.actorId,
since: new Date(event.createdAt),
});
}
}