From e73f34d7e65c854663ea050fbdd101b27bc7fc25 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Sun, 22 Feb 2026 06:59:17 +0000 Subject: [PATCH] optimize breadcrumb --- .../src/core/page/services/page.service.ts | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/apps/server/src/core/page/services/page.service.ts b/apps/server/src/core/page/services/page.service.ts index 98d64f55..07a79c3e 100644 --- a/apps/server/src/core/page/services/page.service.ts +++ b/apps/server/src/core/page/services/page.service.ts @@ -49,6 +49,7 @@ import { EventEmitter2 } from '@nestjs/event-emitter'; import { CollaborationGateway } from '../../../collaboration/collaboration.gateway'; import { markdownToHtml } from '@docmost/editor-ext'; import { WatcherService } from '../../watcher/watcher.service'; +import { sql } from 'kysely'; @Injectable() export class PageService { @@ -736,7 +737,6 @@ export class PageService { 'spaceId', 'deletedAt', ]) - .select((eb) => this.pageRepo.withHasChildren(eb)) .where('id', '=', childPageId) .where('deletedAt', 'is', null) .unionAll((exp) => @@ -752,30 +752,21 @@ export class PageService { 'p.spaceId', 'p.deletedAt', ]) - .select( - exp - .selectFrom('pages as child') - .select((eb) => - eb - .case() - .when(eb.fn.countAll(), '>', 0) - .then(true) - .else(false) - .end() - .as('count'), - ) - .whereRef('child.parentPageId', '=', 'id') - .where('child.deletedAt', 'is', null) - .limit(1) - .as('hasChildren'), - ) - //.select((eb) => this.withHasChildren(eb)) .innerJoin('page_ancestors as pa', 'pa.parentPageId', 'p.id') .where('p.deletedAt', 'is', null), ), ) .selectFrom('page_ancestors') - .selectAll() + .selectAll('page_ancestors') + .select((eb) => + eb.exists( + eb + .selectFrom('pages as child') + .select(sql`1`.as('one')) + .whereRef('child.parentPageId', '=', 'page_ancestors.id') + .where('child.deletedAt', 'is', null), + ).as('hasChildren'), + ) .execute(); return ancestors.reverse();