π The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
Optimisations & improvments
Smaug67392a2b2b1b99cb
diff --git a/frontend/composables/SidebarTreeManager.ts b/frontend/composables/TreeStructure.tssimilarity index 70%rename from frontend/composables/SidebarTreeManager.tsrename to frontend/composables/TreeStructure.tsindex fff773f6..e8f5e163 100644--- a/frontend/composables/SidebarTreeManager.ts+++ b/frontend/composables/TreeStructure.ts@@ -19,18 +19,16 @@ export class TreeStructure {public readonly items: Item[];private itemMap: Map<string, Item>; // Utilisation de Map pour les recherches rapidesprivate childrenMap: Map<string, Item[]>; // Utilisation de Map pour les recherches rapides-constructor(items: Item[]) {this.items = items;this.itemMap = new Map(items.map(item => [item.id, item]));this.childrenMap = new Map();for (const item of items) {- const parentId = item.parent_id;- if (!this.childrenMap.has(parentId)) {- this.childrenMap.set(parentId, []);+ if (!this.childrenMap.has(item.parent_id)) {+ this.childrenMap.set(item.parent_id, []);}- this.childrenMap.get(parentId)!.push(item);+ this.childrenMap.get(item.parent_id)!.push(item);}}@@ -45,6 +43,23 @@ export class TreeStructure {.filter(item => item.parent_id === '' || !this.itemMap.has(item.parent_id) || (item.data.type === 'category' && item.data.role === 2)) // Racines.map(rootItem => this.buildTree(rootItem));}+ public getSubTreeById(id: string): Item | undefined {+ const root = this.getItem(id);+ if (!root) return undefined;+ return this.buildTree(root);+ }+ public treeToArray(tree: Item[]): Item[] {+ const result: Item[] = [];+ const stack: Item[] = [...tree];+ while (stack.length) {+ const node = stack.pop()!;+ result.push(node);+ if (node.childrens) {+ stack.push(...node.childrens);+ }+ }+ return result;+ }// Generate sub treeprivate buildTree(item: Item): Item {diff --git a/frontend/composables/structuresTree.ts b/frontend/composables/structuresTree.tsindex 525abfce..64ae1ef1 100644--- a/frontend/composables/structuresTree.ts+++ b/frontend/composables/structuresTree.ts@@ -1,4 +1,3 @@-import { computed, ref } from 'vue';import { useCategoriesStore, useDocumentsStore, type Category } from '~/stores';function getCollapseState(id: string): boolean {@@ -37,18 +36,14 @@ export function useSidebarTree() {);const allItems = computed(() => [...documents.value, ...categories.value.filter(cat => (cat as Item<Category>).data.role == 1)]);+ const structure = new TreeStructure(allItems.value);++ const tree = computed(() => structure.generateTree());- const tree = computed(() => {- return new TreeStructure(allItems.value).generateTree();- });const filtered = computed(() => {return tree.value.filter(item => {- if (item.data.type === 'category' && workspaceId.value) {- return item.data.workspace_id === workspaceId.value && item.data.role == 1;- }- if (item.data.type === 'document' && workspaceId.value) {- return item.data.category === workspaceId.value;- }+ if (item.data.type === 'category' && workspaceId.value) return item.data.workspace_id === workspaceId.value && item.data.role == 1;+ if (item.data.type === 'document' && workspaceId.value) return item.data.category === workspaceId.value;return true;});});@@ -61,8 +56,12 @@ export function useSidebarTree() {}});};+ const getSubTreeById = (id: string) => {+ return structure.treeToArray(structure.getSubTreeById(id)?.childrens || []);+ };return {+ getSubTreeById,categories,tree,filtered,