perf: Stop copying attachments when moving documents (#3251)

* perf: Stop copying attachments when moving documents

* lint
This commit is contained in:
Tom Moor
2022-03-16 15:18:04 -07:00
committed by GitHub
parent ac2a124714
commit a27af88d4a
3 changed files with 8 additions and 101 deletions

View File

@@ -1,12 +1,9 @@
import Attachment from "@server/models/Attachment";
import {
buildDocument,
buildAttachment,
buildCollection,
buildUser,
} from "@server/test/factories";
import { flushdb, seed } from "@server/test/support";
import parseAttachmentIds from "@server/utils/parseAttachmentIds";
import documentMover from "./documentMover";
beforeEach(() => flushdb());
@@ -110,45 +107,4 @@ describe("documentMover", () => {
expect(response.documents[0].collection.id).toEqual(newCollection.id);
expect(response.documents[1].collection.id).toEqual(newCollection.id);
});
it("should move attachments in children to another collection", async () => {
const { document, user, collection } = await seed();
const newCollection = await buildCollection({
teamId: collection.teamId,
});
const attachment = await buildAttachment({
teamId: user.teamId,
userId: user.id,
});
const newDocument = await buildDocument({
parentDocumentId: document.id,
collectionId: collection.id,
teamId: collection.teamId,
userId: collection.createdById,
title: "Child document",
text: `content ![attachment](${attachment.redirectUrl})`,
});
await collection.addDocumentToStructure(newDocument);
await documentMover({
user,
document,
collectionId: newCollection.id,
parentDocumentId: undefined,
index: 0,
ip,
});
// check document ids where updated
await newDocument.reload();
expect(newDocument.collectionId).toBe(newCollection.id);
// check new attachment was created pointint to same key
const attachmentIds = parseAttachmentIds(newDocument.text);
const newAttachment = await Attachment.findByPk(attachmentIds[0]);
expect(newAttachment?.documentId).toBe(newDocument.id);
expect(newAttachment?.key).toBe(attachment.key);
await document.reload();
expect(document.collectionId).toBe(newCollection.id);
});
});