diff --git a/server/models/Collection.test.ts b/server/models/Collection.test.ts index 3bd8947b7..d7d7407fc 100644 --- a/server/models/Collection.test.ts +++ b/server/models/Collection.test.ts @@ -111,6 +111,10 @@ describe("#addDocumentToStructure", () => { await collection.addDocumentToStructure(newDocument); expect(collection.documentStructure!.length).toBe(1); expect(collection.documentStructure![0].id).toBe(id); + + // should not append multiple times + await collection.addDocumentToStructure(newDocument); + expect(collection.documentStructure!.length).toBe(1); }); test("should add with an index", async () => { diff --git a/server/models/Collection.ts b/server/models/Collection.ts index 3b1543a8b..4c4d46ba2 100644 --- a/server/models/Collection.ts +++ b/server/models/Collection.ts @@ -647,6 +647,10 @@ class Collection extends ParanoidModel { this.documentStructure = []; } + if (this.getDocumentTree(document.id)) { + return this; + } + // If moving existing document with children, use existing structure const documentJson = { ...(await document.toNavigationNode(options)),