mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
fix(core): improve tag list performance (#11353)
This commit is contained in:
@@ -60,7 +60,6 @@ export class TagList extends Entity {
|
||||
id: tag.id,
|
||||
title: get(tag.value$),
|
||||
color: get(tag.color$),
|
||||
pageCount: get(tag.pageIds$).length,
|
||||
createDate: get(tag.createDate$),
|
||||
updatedDate: get(tag.updateDate$),
|
||||
};
|
||||
|
||||
@@ -64,14 +64,5 @@ export class Tag extends Entity<{ id: string }> {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated performance issue here, use with caution until it is fixed
|
||||
* @fixme(EYHN): page.meta$ has performance issue
|
||||
*/
|
||||
readonly pageIds$ = LiveData.computed(get => {
|
||||
const pages = get(this.docs.list.docs$);
|
||||
return pages
|
||||
.filter(page => get(page.meta$).tags?.includes(this.id))
|
||||
.map(page => page.id);
|
||||
});
|
||||
readonly pageIds$ = LiveData.from(this.store.watchTagPageIds(this.id), []);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import type { Tag, Tag as TagSchema } from '@affine/env/filter';
|
||||
import type { DocsPropertiesMeta } from '@blocksuite/affine/store';
|
||||
import { LiveData, Store } from '@toeverything/infra';
|
||||
import {
|
||||
LiveData,
|
||||
Store,
|
||||
yjsObserveByPath,
|
||||
yjsObserveDeep,
|
||||
} from '@toeverything/infra';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map, Observable, switchMap } from 'rxjs';
|
||||
import { Array as YArray } from 'yjs';
|
||||
|
||||
import type { WorkspaceService } from '../../workspace';
|
||||
|
||||
@@ -119,4 +125,32 @@ export class TagStore extends Store {
|
||||
...tagInfo,
|
||||
});
|
||||
}
|
||||
|
||||
watchTagPageIds(id: string) {
|
||||
return yjsObserveByPath(
|
||||
this.workspaceService.workspace.rootYDoc.getMap('meta'),
|
||||
'pages'
|
||||
).pipe(
|
||||
switchMap(yjsObserveDeep),
|
||||
map(meta => {
|
||||
if (meta instanceof YArray) {
|
||||
return meta
|
||||
.map(v => {
|
||||
const tags = v.get('tags') as YArray<string> | undefined;
|
||||
if (tags instanceof YArray) {
|
||||
for (const tagId of tags.toArray()) {
|
||||
if (tagId === id) {
|
||||
return v.get('id') as string;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.filter(Boolean) as string[];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user