optimize breadcrumb

This commit is contained in:
Philipinho
2026-02-22 06:59:17 +00:00
parent 9fd33d1e15
commit e73f34d7e6
@@ -49,6 +49,7 @@ import { EventEmitter2 } from '@nestjs/event-emitter';
import { CollaborationGateway } from '../../../collaboration/collaboration.gateway'; import { CollaborationGateway } from '../../../collaboration/collaboration.gateway';
import { markdownToHtml } from '@docmost/editor-ext'; import { markdownToHtml } from '@docmost/editor-ext';
import { WatcherService } from '../../watcher/watcher.service'; import { WatcherService } from '../../watcher/watcher.service';
import { sql } from 'kysely';
@Injectable() @Injectable()
export class PageService { export class PageService {
@@ -736,7 +737,6 @@ export class PageService {
'spaceId', 'spaceId',
'deletedAt', 'deletedAt',
]) ])
.select((eb) => this.pageRepo.withHasChildren(eb))
.where('id', '=', childPageId) .where('id', '=', childPageId)
.where('deletedAt', 'is', null) .where('deletedAt', 'is', null)
.unionAll((exp) => .unionAll((exp) =>
@@ -752,30 +752,21 @@ export class PageService {
'p.spaceId', 'p.spaceId',
'p.deletedAt', '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') .innerJoin('page_ancestors as pa', 'pa.parentPageId', 'p.id')
.where('p.deletedAt', 'is', null), .where('p.deletedAt', 'is', null),
), ),
) )
.selectFrom('page_ancestors') .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(); .execute();
return ancestors.reverse(); return ancestors.reverse();