diff --git a/packages/common/infra/src/page/record-list.ts b/packages/common/infra/src/page/record-list.ts index 697fb745d6..9405dfa137 100644 --- a/packages/common/infra/src/page/record-list.ts +++ b/packages/common/infra/src/page/record-list.ts @@ -11,6 +11,8 @@ export class PageRecordList { private readonly localState: WorkspaceLocalState ) {} + private readonly recordsPool = new Map(); + public readonly records$ = LiveData.from( new Observable(subscriber => { const emit = () => { @@ -29,7 +31,15 @@ export class PageRecordList { }).pipe( distinctUntilChanged((p, c) => isEqual(p, c)), map(ids => - ids.map(id => new PageRecord(id, this.workspace, this.localState)) + ids.map(id => { + const exists = this.recordsPool.get(id); + if (exists) { + return exists; + } + const record = new PageRecord(id, this.workspace, this.localState); + this.recordsPool.set(id, record); + return record; + }) ) ), [] diff --git a/packages/common/infra/src/page/record.ts b/packages/common/infra/src/page/record.ts index b117ef3245..4abc68177d 100644 --- a/packages/common/infra/src/page/record.ts +++ b/packages/common/infra/src/page/record.ts @@ -1,5 +1,6 @@ import type { DocMeta } from '@blocksuite/store'; -import { Observable } from 'rxjs'; +import { isEqual } from 'lodash-es'; +import { distinctUntilChanged, Observable } from 'rxjs'; import { LiveData } from '../livedata'; import type { Workspace, WorkspaceLocalState } from '../workspace'; @@ -14,7 +15,7 @@ export class PageRecord { ) {} meta$ = LiveData.from( - new Observable(subscriber => { + new Observable(subscriber => { const emit = () => { const meta = this.workspace.docCollection.meta.docMetas.find( page => page.id === this.id @@ -32,7 +33,7 @@ export class PageRecord { return () => { dispose(); }; - }), + }).pipe(distinctUntilChanged((p, c) => isEqual(p, c))), { id: this.id, title: '',