mirror of
https://github.com/outline/outline.git
synced 2026-11-21 21:44:30 +03:00
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.
27 lines
868 B
TypeScript
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),
|
|
});
|
|
}
|
|
}
|