refactor(core): use new backlink indexer (#7296)

This commit is contained in:
EYHN
2024-07-02 09:18:01 +00:00
parent 40e381e272
commit 27d0fc5108
33 changed files with 826 additions and 357 deletions

View File

@@ -29,6 +29,23 @@ export class DocRecordList extends Entity {
[]
);
public readonly trashDocs$ = LiveData.from<DocRecord[]>(
this.store.watchTrashDocIds().pipe(
map(ids =>
ids.map(id => {
const exists = this.pool.get(id);
if (exists) {
return exists;
}
const record = this.framework.createEntity(DocRecord, { id });
this.pool.set(id, record);
return record;
})
)
),
[]
);
public readonly isReady$ = LiveData.from(
this.store.watchDocListReady(),
false

View File

@@ -58,5 +58,6 @@ export class DocRecord extends Entity<{ id: string }> {
}
title$ = this.meta$.map(meta => meta.title ?? '');
trash$ = this.meta$.map(meta => meta.trash ?? false);
}

View File

@@ -41,7 +41,29 @@ export class DocsStore extends Store {
return () => {
dispose();
};
}).pipe(distinctUntilChanged((p, c) => isEqual(p, c)));
});
}
watchTrashDocIds() {
return new Observable<string[]>(subscriber => {
const emit = () => {
subscriber.next(
this.workspaceService.workspace.docCollection.meta.docMetas
.map(v => (v.trash ? v.id : null))
.filter(Boolean) as string[]
);
};
emit();
const dispose =
this.workspaceService.workspace.docCollection.meta.docMetaUpdated.on(
emit
).dispose;
return () => {
dispose();
};
});
}
watchDocMeta(id: string) {

View File

@@ -233,7 +233,6 @@ export class IndexedDBJobQueue<J> implements JobQueue<J> {
fromPromise(async () => {
const trx = this.database.transaction(['jobs'], 'readonly');
const remaining = await trx.objectStore('jobs').count();
console.log(remaining);
return { remaining };
})
)