From 02447c1c487cb3e100373b891ade4ce47bef1f29 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Mon, 2 Feb 2026 13:54:21 +0000 Subject: [PATCH] fix: exclude content from history listing --- .../listeners/history.listener.ts | 4 +- apps/server/src/core/page/page.controller.ts | 1 - .../page/services/page-history.service.ts | 4 +- .../database/repos/page/page-history.repo.ts | 38 +++++++++++++++---- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/apps/server/src/collaboration/listeners/history.listener.ts b/apps/server/src/collaboration/listeners/history.listener.ts index 26f3a56e..e0d40838 100644 --- a/apps/server/src/collaboration/listeners/history.listener.ts +++ b/apps/server/src/collaboration/listeners/history.listener.ts @@ -32,7 +32,9 @@ export class HistoryListener { return; } - const lastHistory = await this.pageHistoryRepo.findPageLastHistory(page.id); + const lastHistory = await this.pageHistoryRepo.findPageLastHistory(page.id, { + includeContent: true, + }); if ( !lastHistory || diff --git a/apps/server/src/core/page/page.controller.ts b/apps/server/src/core/page/page.controller.ts index 97275440..08daecf8 100644 --- a/apps/server/src/core/page/page.controller.ts +++ b/apps/server/src/core/page/page.controller.ts @@ -215,7 +215,6 @@ export class PageController { } } - // TODO: scope to workspaces @HttpCode(HttpStatus.OK) @Post('/history') async getPageHistory( diff --git a/apps/server/src/core/page/services/page-history.service.ts b/apps/server/src/core/page/services/page-history.service.ts index a3e96639..9155638f 100644 --- a/apps/server/src/core/page/services/page-history.service.ts +++ b/apps/server/src/core/page/services/page-history.service.ts @@ -9,7 +9,9 @@ export class PageHistoryService { constructor(private pageHistoryRepo: PageHistoryRepo) {} async findById(historyId: string): Promise { - return await this.pageHistoryRepo.findById(historyId); + return await this.pageHistoryRepo.findById(historyId, { + includeContent: true, + }); } async findHistoryByPageId( diff --git a/apps/server/src/database/repos/page/page-history.repo.ts b/apps/server/src/database/repos/page/page-history.repo.ts index 7152d8e3..c61c7e88 100644 --- a/apps/server/src/database/repos/page/page-history.repo.ts +++ b/apps/server/src/database/repos/page/page-history.repo.ts @@ -17,15 +17,32 @@ import { DB } from '@docmost/db/types/db'; export class PageHistoryRepo { constructor(@InjectKysely() private readonly db: KyselyDB) {} + private baseFields: Array = [ + 'id', + 'pageId', + 'slugId', + 'title', + 'icon', + 'coverPhoto', + 'lastUpdatedById', + 'spaceId', + 'workspaceId', + 'createdAt', + ]; + async findById( pageHistoryId: string, - trx?: KyselyTransaction, + opts?: { + includeContent?: boolean; + trx?: KyselyTransaction; + }, ): Promise { - const db = dbOrTx(this.db, trx); + const db = dbOrTx(this.db, opts?.trx); return await db .selectFrom('pageHistory') - .selectAll() + .select(this.baseFields) + .$if(opts?.includeContent, (qb) => qb.select('content')) .select((eb) => this.withLastUpdatedBy(eb)) .where('id', '=', pageHistoryId) .executeTakeFirst(); @@ -63,7 +80,7 @@ export class PageHistoryRepo { async findPageHistoryByPageId(pageId: string, pagination: PaginationOptions) { const query = this.db .selectFrom('pageHistory') - .selectAll() + .select(this.baseFields) .select((eb) => this.withLastUpdatedBy(eb)) .where('pageId', '=', pageId); @@ -76,12 +93,19 @@ export class PageHistoryRepo { }); } - async findPageLastHistory(pageId: string, trx?: KyselyTransaction) { - const db = dbOrTx(this.db, trx); + async findPageLastHistory( + pageId: string, + opts?: { + includeContent?: boolean; + trx?: KyselyTransaction; + }, + ) { + const db = dbOrTx(this.db, opts?.trx); return await db .selectFrom('pageHistory') - .selectAll() + .select(this.baseFields) + .$if(opts?.includeContent, (qb) => qb.select('content')) .where('pageId', '=', pageId) .limit(1) .orderBy('createdAt', 'desc')