Implement background migration using index
This commit is contained in:
parent
9ca6fd6498
commit
86e48a5713
1 changed files with 28 additions and 9 deletions
|
@ -90,18 +90,37 @@
|
||||||
storage.fetch();
|
storage.fetch();
|
||||||
|
|
||||||
const idleDetector = new IdleDetector();
|
const idleDetector = new IdleDetector();
|
||||||
|
let isMigrationWithIndexComplete = false;
|
||||||
|
let isMigrationWithoutIndexComplete = false;
|
||||||
idleDetector.on('idle', async () => {
|
idleDetector.on('idle', async () => {
|
||||||
const NUM_MESSAGES_PER_BATCH = 1;
|
const NUM_MESSAGES_PER_BATCH = 1;
|
||||||
const database = Migrations0DatabaseWithAttachmentData.getDatabase();
|
|
||||||
const batch = await MessageDataMigrator.processNextBatchWithoutIndex({
|
|
||||||
databaseName: database.name,
|
|
||||||
minDatabaseVersion: database.version,
|
|
||||||
numMessagesPerBatch: NUM_MESSAGES_PER_BATCH,
|
|
||||||
upgradeMessageSchema,
|
|
||||||
});
|
|
||||||
console.log('Upgrade message schema:', batch);
|
|
||||||
|
|
||||||
if (batch.done) {
|
if (!isMigrationWithIndexComplete) {
|
||||||
|
const batchWithIndex = await MessageDataMigrator.processNext({
|
||||||
|
BackboneMessage: Whisper.Message,
|
||||||
|
BackboneMessageCollection: Whisper.MessageCollection,
|
||||||
|
numMessagesPerBatch: NUM_MESSAGES_PER_BATCH,
|
||||||
|
upgradeMessageSchema,
|
||||||
|
});
|
||||||
|
console.log('Upgrade message schema (with index):', batchWithIndex);
|
||||||
|
isMigrationWithIndexComplete = batchWithIndex.done;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isMigrationWithoutIndexComplete) {
|
||||||
|
const database = Migrations0DatabaseWithAttachmentData.getDatabase();
|
||||||
|
const batchWithoutIndex = await MessageDataMigrator.processNextBatchWithoutIndex({
|
||||||
|
databaseName: database.name,
|
||||||
|
minDatabaseVersion: database.version,
|
||||||
|
numMessagesPerBatch: NUM_MESSAGES_PER_BATCH,
|
||||||
|
upgradeMessageSchema,
|
||||||
|
});
|
||||||
|
console.log('Upgrade message schema (without index):', batchWithoutIndex);
|
||||||
|
isMigrationWithoutIndexComplete = batchWithoutIndex.done;
|
||||||
|
}
|
||||||
|
|
||||||
|
const areAllMigrationsComplete = isMigrationWithIndexComplete &&
|
||||||
|
isMigrationWithoutIndexComplete;
|
||||||
|
if (areAllMigrationsComplete) {
|
||||||
idleDetector.stop();
|
idleDetector.stop();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue