fix: Do not store the attachment id map on every JSON import task (#14851)

This commit is contained in:
Tom Moor authored and GitHub committed 2026-12-02 09:42:34 -05:00
1 parent f43e077389
commit 479765c808
3 files changed
+37 -12

No files matched your search

+12 -10
View File
@@ -341,7 +341,6 @@ export default class JSONAPIImportTask extends APIImportTask<Service> {
icon: c.export.icon,
color: c.export.color,
data: c.export.data ?? ProsemirrorDataHelper.getEmpty(),
attachmentIdMap,
})),
];
@@ -363,7 +362,7 @@ export default class JSONAPIImportTask extends APIImportTask<Service> {
// depth-ordered cascade of ImportTask rows so parent FKs are always
// satisfied at child-doc creation time.
const childTasksInput: ImportTaskInput<Service> = collections.flatMap(
(c) => c.children.map((d) => this.toPageInput(d, attachmentIdMap))
(c) => c.children.map((d) => this.toPageInput(d))
);
return { taskOutput: collectionOutputs, childTasksInput };
@@ -378,11 +377,19 @@ export default class JSONAPIImportTask extends APIImportTask<Service> {
const taskOutput: ImportTaskOutput = [];
const childTasksInput: JSONPageImportTaskInputItem[] = [];
// Built from the manifest so the map is not serialized into every task input.
const attachmentIdMap: Record<string, string> = Object.fromEntries(
(importTask.import.scratch?.manifest ?? []).map((m) => [
m.externalId,
m.id,
])
);
const items = importTask.input as JSONPageImportTaskInputItem[];
for (const item of items) {
const transformed = rewriteAttachmentReferences(
item.data,
item.attachmentIdMap
attachmentIdMap
) as ProsemirrorDoc;
taskOutput.push({
@@ -529,13 +536,9 @@ export default class JSONAPIImportTask extends APIImportTask<Service> {
* each tree-depth runs as its own task wave.
*
* @param doc The discovered document, including its descendants.
* @param attachmentIdMap External attachment id → new internal id map.
* @returns A self-contained per-page task input.
*/
private toPageInput(
doc: DiscoveredDocument,
attachmentIdMap: Record<string, string>
): JSONPageImportTaskInputItem {
private toPageInput(doc: DiscoveredDocument): JSONPageImportTaskInputItem {
const exported = doc.export;
return {
externalId: doc.externalId,
@@ -552,9 +555,8 @@ export default class JSONAPIImportTask extends APIImportTask<Service> {
createdAt: exported.createdAt,
updatedAt: exported.updatedAt,
publishedAt: exported.publishedAt,
attachmentIdMap,
children: doc.children.length
? doc.children.map((c) => this.toPageInput(c, attachmentIdMap))
? doc.children.map((c) => this.toPageInput(c))
: undefined,
};
}