fix(core): collections data migration without blocking data reads (#4866)

This commit is contained in:
3720
2023-11-08 20:38:43 +08:00
committed by GitHub
parent c55565ee71
commit da2821eaac

View File

@@ -101,7 +101,6 @@ export const pageCollectionBaseAtom =
const migrateCollectionsFromIdbData = async (
workspace: Workspace
): Promise<Collection[]> => {
workspace.awarenessStore.awareness.emit('change log');
const localCRUD = get(localCollectionCRUDAtom);
const collections = await getCollections(localCRUD);
const result = collections.filter(v => v.workspaceId === workspace.id);
@@ -149,18 +148,17 @@ export const pageCollectionBaseAtom =
return new Observable<BaseCollectionsDataType>(subscriber => {
const group = new DisposableGroup();
currentWorkspacePromise.then(async currentWorkspace => {
const collectionsFromLocal =
await migrateCollectionsFromIdbData(currentWorkspace);
const collectionFromUserSetting =
await migrateCollectionsFromUserData(currentWorkspace);
const workspaceSetting = getWorkspaceSetting(currentWorkspace);
if (collectionsFromLocal.length || collectionFromUserSetting.length) {
// migrate collections
workspaceSetting.addCollection(
...collectionFromUserSetting,
...collectionsFromLocal
);
}
migrateCollectionsFromIdbData(currentWorkspace).then(collections => {
if (collections.length) {
workspaceSetting.addCollection(...collections);
}
});
migrateCollectionsFromUserData(currentWorkspace).then(collections => {
if (collections.length) {
workspaceSetting.addCollection(...collections);
}
});
subscriber.next({
loading: false,
collections: workspaceSetting.collections,