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