core: fix migrate to sqlite progress reporting

This commit is contained in:
Abdullah Atta
2024-04-18 12:53:16 +05:00
parent 3efe541869
commit 271913ba20
2 changed files with 11 additions and 12 deletions

View File

@@ -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);

View File

@@ -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
);
}
}