Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

core: fix migrate to sqlite progress reporting

Abdullah Atta271913ba206c
diff --git a/packages/core/src/database/index.ts b/packages/core/src/database/index.ts
index b0d63ee02..cf577bf9a 100644
--- a/packages/core/src/database/index.ts
+++ b/packages/core/src/database/index.ts
@@ -336,10 +336,10 @@ export type SQLiteOptions = {
};
export async function createDatabase(name: string, options: SQLiteOptions) {
const db = new Kysely<RawDatabaseSchema>({
- log: (event) => {
- if (event.queryDurationMillis > 5)
- console.warn(event.query.sql, event.queryDurationMillis);
- },
+ // log: (event) => {
+ // if (event.queryDurationMillis > 5)
+ // console.warn(event.query.sql, event.queryDurationMillis);
+ // },
dialect: options.dialect(name, async () => {
await db.connection().execute(async (db) => {
await setupDatabase(db, options);
diff --git a/packages/core/src/database/migrator.ts b/packages/core/src/database/migrator.ts
index 211c87eeb..2feb58baf 100644
--- a/packages/core/src/database/migrator.ts
+++ b/packages/core/src/database/migrator.ts
@@ -99,14 +99,20 @@ class Migrator {
await indexedCollection.init();
await table.init();
+ let count = 0;
for await (const entries of indexedCollection.iterate(100)) {
await this.migrateToSQLite(
db,
table,
- collection.name,
entries.map((i) => i[1]),
version
);
+ sendMigrationProgressEvent(
+ db.eventManager,
+ collection.name,
+ indexedCollection.indexer.indices.length,
+ (count += 100)
+ );
}
await indexedCollection.clear();
}
@@ -123,7 +129,6 @@ class Migrator {
private async migrateToSQLite(
db: Database,
table: SQLCollection<keyof DatabaseSchema>,
- type: keyof Collections,
items: (RawItem | undefined)[],
version: number
) {
@@ -168,12 +173,6 @@ class Migrator {
if (toAdd.length > 0) {
await table.put(toAdd as any);
- sendMigrationProgressEvent(
- db.eventManager,
- type,
- toAdd.length,
- toAdd.length
- );
}
}