Files
outline/server/queues/processors/RevisionsProcessor.ts
Tom Moor d3235250a8 perf: Move text serialization to task runner (#8589)
* perf: Move text serialization to task runner

* tsc

* test

* refactor

* fix: Restore previous default of toMarkdown behavior

* Stop writing text to revisions
2025-03-02 08:21:50 -08:00

58 lines
1.7 KiB
TypeScript

import isEqual from "fast-deep-equal";
import revisionCreator from "@server/commands/revisionCreator";
import { Revision, Document, User } from "@server/models";
import { DocumentEvent, RevisionEvent, Event } from "@server/types";
import DocumentUpdateTextTask from "../tasks/DocumentUpdateTextTask";
import BaseProcessor from "./BaseProcessor";
export default class RevisionsProcessor extends BaseProcessor {
static applicableEvents: Event["name"][] = [
"documents.publish",
"documents.update",
"documents.update.debounced",
];
async perform(event: DocumentEvent | RevisionEvent) {
switch (event.name) {
case "documents.publish":
case "documents.update.debounced":
case "documents.update": {
if (event.name === "documents.update" && !event.data.done) {
return;
}
const document = await Document.findByPk(event.documentId, {
paranoid: false,
rejectOnEmpty: true,
});
const previous = await Revision.findLatest(document.id);
// we don't create revisions if identical to previous revision, this can happen if a manual
// revision was created from another service or user.
if (
previous &&
isEqual(document.content, previous.content) &&
document.title === previous.title
) {
return;
}
await DocumentUpdateTextTask.schedule(event);
const user = await User.findByPk(event.actorId, {
paranoid: false,
rejectOnEmpty: true,
});
await revisionCreator({
event,
user,
document,
});
break;
}
default:
}
}
}