fix(electron): only update db after data changed (#5226)

This commit is contained in:
Joooye_34
2023-12-07 12:27:53 +00:00
parent 70c376fac8
commit 761c3c2551

View File

@@ -1,4 +1,3 @@
import { equal } from 'node:assert';
import { resolve } from 'node:path';
import { SqliteConnection } from '@affine/native';
@@ -78,19 +77,23 @@ export const migrateToLatest = async (
};
await downloadBinary(rootDoc, true);
const result = await forceUpgradePages(rootDoc, schema);
equal(result, true, 'migrateWorkspace should return boolean value');
const uploadBinary = async (doc: YDoc, isRoot: boolean) => {
await connection.replaceUpdates(doc.guid, [
{ docId: isRoot ? undefined : doc.guid, data: encodeStateAsUpdate(doc) },
]);
// connection..applyUpdate(encodeStateAsUpdate(doc), 'self', doc.guid)
await Promise.all(
[...doc.subdocs].map(subdoc => {
return uploadBinary(subdoc, false);
})
);
};
await uploadBinary(rootDoc, true);
if (result) {
const uploadBinary = async (doc: YDoc, isRoot: boolean) => {
await connection.replaceUpdates(doc.guid, [
{
docId: isRoot ? undefined : doc.guid,
data: encodeStateAsUpdate(doc),
},
]);
// connection..applyUpdate(encodeStateAsUpdate(doc), 'self', doc.guid)
await Promise.all(
[...doc.subdocs].map(subdoc => {
return uploadBinary(subdoc, false);
})
);
};
await uploadBinary(rootDoc, true);
}
await connection.close();
};