mirror of
https://github.com/outline/outline.git
synced 2026-12-04 02:20:17 +03:00
fix: Do not store the attachment id map on every JSON import task (#14851)
This commit is contained in:
1 parent
f43e077389
commit
479765c808
3 files changed
+37
-12
No files matched your search
@@ -347,6 +347,31 @@ describe("JSONAPIImportTask", () => {
|
||||
expect(attachments.length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
it("rewrites document attachment references without storing the map on tasks", async () => {
|
||||
const admin = await buildAdmin();
|
||||
const { importId } = await runImport({
|
||||
teamId: admin.teamId,
|
||||
createdById: admin.id,
|
||||
zipPath: zip.filePath,
|
||||
});
|
||||
|
||||
const attachments = await Attachment.findAll({
|
||||
where: { teamId: admin.teamId },
|
||||
});
|
||||
const documents = await Document.findAll({
|
||||
where: { apiImportId: importId },
|
||||
});
|
||||
const tasks = await ImportTask.findAll({ where: { importId } });
|
||||
const content = JSON.stringify(documents.map((d) => d.content));
|
||||
|
||||
expect(
|
||||
attachments.some((a) => content.includes(Attachment.getRedirectUrl(a.id)))
|
||||
).toBe(true);
|
||||
expect(JSON.stringify(tasks.map((t) => t.input))).not.toContain(
|
||||
"attachmentIdMap"
|
||||
);
|
||||
});
|
||||
|
||||
it("deletes the source archive after the import completes", async () => {
|
||||
const admin = await buildAdmin();
|
||||
const sourceAttachment = await buildAttachment({
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -190,8 +190,6 @@ export interface JSONPageImportTaskInputItem {
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
publishedAt?: string | null;
|
||||
/** Map of external attachment id → manifest entry id, scoped to this doc. */
|
||||
attachmentIdMap: Record<string, string>;
|
||||
children?: JSONPageImportTaskInputItem[];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user