From 1fc38e941ebf3765c56d8fcfb1ec1146973aeb56 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Sat, 13 Sep 2025 04:01:45 +0200 Subject: [PATCH] fix(collapse-subtree): improve performance of collapsing subtrees from O(n) to O(v) Only collapse currently expanded descendants instead of the entire subtree. Assuming n is the number of subnotes and v is the number of opened notes --- apps/server/src/routes/api/branches.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/server/src/routes/api/branches.ts b/apps/server/src/routes/api/branches.ts index bed1c93b7..4cd570fcb 100644 --- a/apps/server/src/routes/api/branches.ts +++ b/apps/server/src/routes/api/branches.ts @@ -163,6 +163,7 @@ function setExpandedForSubtree(req: Request) { SELECT branches.branchId, branches.noteId FROM branches JOIN tree ON branches.parentNoteId = tree.noteId WHERE branches.isDeleted = 0 + AND branches.isExpanded = 1 ) SELECT branchId FROM tree`, [branchId]