fix: sqlite provider import sub doc db file (#2991)

Co-authored-by: Alex Yang <himself65@outlook.com>
This commit is contained in:
Peng Xiao
2023-07-05 01:47:42 +08:00
committed by Alex Yang
parent c5f5e606b0
commit 093851ec0c
7 changed files with 49 additions and 39 deletions

View File

@@ -173,17 +173,18 @@ export const createSQLiteDBDownloadProvider: DocProviderCreator = (
Y.applyUpdate(doc, updates, sqliteOrigin);
}
const diff = Y.encodeStateAsUpdate(doc, updates);
const mergedUpdates = Y.encodeStateAsUpdate(doc);
// also apply updates to sqlite
await apis.db.applyDocUpdate(id, diff, subdocId);
await apis.db.applyDocUpdate(id, mergedUpdates, subdocId);
return true;
}
async function syncAllUpdates(doc: Doc) {
if (await syncUpdates(doc)) {
const subdocs = Array.from(doc.subdocs).filter(d => d.shouldLoad);
// load all subdocs
const subdocs = Array.from(doc.subdocs);
await Promise.all(subdocs.map(syncAllUpdates));
}
}
@@ -198,7 +199,7 @@ export const createSQLiteDBDownloadProvider: DocProviderCreator = (
disconnected = true;
},
sync: async () => {
logger.info('connect indexeddb provider', id);
logger.info('connect sqlite download provider', id);
try {
await syncAllUpdates(rootDoc);
_resolve();