Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(infra): large page list performance #6319

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/common/infra/src/page/record-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export class PageRecordList {
private readonly localState: WorkspaceLocalState
) {}

private readonly recordsPool = new Map<string, PageRecord>();

public readonly records$ = LiveData.from<PageRecord[]>(
new Observable<string[]>(subscriber => {
const emit = () => {
Expand All @@ -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;
})
)
),
[]
Expand Down
7 changes: 4 additions & 3 deletions packages/common/infra/src/page/record.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -14,7 +15,7 @@ export class PageRecord {
) {}

meta$ = LiveData.from<DocMeta>(
new Observable(subscriber => {
new Observable<DocMeta>(subscriber => {
const emit = () => {
const meta = this.workspace.docCollection.meta.docMetas.find(
page => page.id === this.id
Expand All @@ -32,7 +33,7 @@ export class PageRecord {
return () => {
dispose();
};
}),
}).pipe(distinctUntilChanged((p, c) => isEqual(p, c))),
{
id: this.id,
title: '',
Expand Down
Loading