mirror of
https://github.com/toeverything/AFFiNE.git
synced 2025-01-04 23:32:31 +03:00
fix(infra): large page list performance (#6319)
This commit is contained in:
parent
8ee9f6ec05
commit
b6bba523ff
@ -11,6 +11,8 @@ export class PageRecordList {
|
|||||||
private readonly localState: WorkspaceLocalState
|
private readonly localState: WorkspaceLocalState
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
private readonly recordsPool = new Map<string, PageRecord>();
|
||||||
|
|
||||||
public readonly records$ = LiveData.from<PageRecord[]>(
|
public readonly records$ = LiveData.from<PageRecord[]>(
|
||||||
new Observable<string[]>(subscriber => {
|
new Observable<string[]>(subscriber => {
|
||||||
const emit = () => {
|
const emit = () => {
|
||||||
@ -29,7 +31,15 @@ export class PageRecordList {
|
|||||||
}).pipe(
|
}).pipe(
|
||||||
distinctUntilChanged((p, c) => isEqual(p, c)),
|
distinctUntilChanged((p, c) => isEqual(p, c)),
|
||||||
map(ids =>
|
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;
|
||||||
|
})
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
[]
|
[]
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import type { DocMeta } from '@blocksuite/store';
|
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 { LiveData } from '../livedata';
|
||||||
import type { Workspace, WorkspaceLocalState } from '../workspace';
|
import type { Workspace, WorkspaceLocalState } from '../workspace';
|
||||||
@ -14,7 +15,7 @@ export class PageRecord {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
meta$ = LiveData.from<DocMeta>(
|
meta$ = LiveData.from<DocMeta>(
|
||||||
new Observable(subscriber => {
|
new Observable<DocMeta>(subscriber => {
|
||||||
const emit = () => {
|
const emit = () => {
|
||||||
const meta = this.workspace.docCollection.meta.docMetas.find(
|
const meta = this.workspace.docCollection.meta.docMetas.find(
|
||||||
page => page.id === this.id
|
page => page.id === this.id
|
||||||
@ -32,7 +33,7 @@ export class PageRecord {
|
|||||||
return () => {
|
return () => {
|
||||||
dispose();
|
dispose();
|
||||||
};
|
};
|
||||||
}),
|
}).pipe(distinctUntilChanged((p, c) => isEqual(p, c))),
|
||||||
{
|
{
|
||||||
id: this.id,
|
id: this.id,
|
||||||
title: '',
|
title: '',
|
||||||
|
Loading…
Reference in New Issue
Block a user