Files
outline/server/queues/tasks/DocumentUpdateTextTask.ts
T
Tom Moor d0ede882c6 perf: More memory improvements (#12539)
* perf: Lazy import mailparser, @fast-csv, and franc deps

Moves heavy dependencies off the startup path into the narrow async code
paths that actually use them, mirroring the mammoth lazy-import change:

- mailparser: only needed for Confluence Word imports (confluenceToHtml)
- @fast-csv/parse: only needed for CSV imports (csvToMarkdown)
- franc / iso-639-3: only needed by the DocumentUpdateText worker task

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* perf: Lazy import jsdom dep

jsdom is one of the heaviest server dependencies but is only needed for
HTML export (ProsemirrorHelper.toHTML) and HTML import
(DocumentConverter.htmlToProsemirror). Move it to a lazy `await import`
inside those methods so its dependency tree stays off the startup path.

Both methods become async; all callers were already in async contexts.
The type-only usage in patchGlobalEnv is now an `import type`.
2026-05-30 17:31:04 -04:00

33 lines
1.1 KiB
TypeScript

import { Node } from "prosemirror-model";
import { schema, serializer } from "@server/editor";
import { Document } from "@server/models";
import type { DocumentEvent } from "@server/types";
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
import { BaseTask } from "./base/BaseTask";
export default class DocumentUpdateTextTask extends BaseTask<DocumentEvent> {
public async perform(event: DocumentEvent) {
const document = await Document.findByPk(event.documentId);
if (!document?.content) {
return;
}
const node = Node.fromJSON(schema, document.content);
document.text = serializer.serialize(node);
// Loaded lazily to keep the language-detection corpus off the startup path —
// only this worker task needs it.
const [{ franc }, { iso6393To1 }] = await Promise.all([
import("franc"),
import("iso-639-3"),
]);
const language = franc(DocumentHelper.toPlainText(document), {
minLength: 50,
});
document.language = iso6393To1[language];
await document.save({ silent: true });
}
}