Replace startup with attachment background migration

Iterates through `Message::id` index.
pull/1/head
Daniel Gasienica 7 years ago
parent c853d1bccd
commit 77b1f3c505

@ -86,29 +86,23 @@
console.log('Run migrations on database with attachment data'); console.log('Run migrations on database with attachment data');
await Migrations0DatabaseWithAttachmentData.run({ Backbone }); await Migrations0DatabaseWithAttachmentData.run({ Backbone });
await MessageDataMigrator.dangerouslyProcessAllWithoutIndex({
databaseName: Migrations0DatabaseWithAttachmentData.getDatabase().name,
minDatabaseVersion: Migrations0DatabaseWithAttachmentData.getDatabase().version,
upgradeMessageSchema,
});
console.log('Storage fetch'); console.log('Storage fetch');
storage.fetch(); storage.fetch();
const idleDetector = new IdleDetector(); const idleDetector = new IdleDetector();
idleDetector.on('idle', async () => { idleDetector.on('idle', async () => {
// const database = Migrations0DatabaseWithAttachmentData.getDatabase(); const database = Migrations0DatabaseWithAttachmentData.getDatabase();
// const batch = await MessageDataMigrator.processNextBatchWithoutIndex({ const batch = await MessageDataMigrator.processNextBatchWithoutIndex({
// databaseName: database.name, databaseName: database.name,
// minDatabaseVersion: database.version, minDatabaseVersion: database.version,
// upgradeMessageSchema, upgradeMessageSchema,
// }); });
// console.log('Upgrade message schema:', batch); console.log('Upgrade message schema:', batch);
// if (batch.done) { if (batch.done) {
// idleDetector.stop(); idleDetector.stop();
// } }
}); });
/* eslint-disable */ /* eslint-disable */

@ -3,8 +3,8 @@
const EventEmitter = require('events'); const EventEmitter = require('events');
const POLL_INTERVAL_MS = 30 * 1000; const POLL_INTERVAL_MS = 15 * 1000;
const IDLE_THRESHOLD_MS = 25; const IDLE_THRESHOLD_MS = 20;
class IdleDetector extends EventEmitter { class IdleDetector extends EventEmitter {
constructor() { constructor() {
@ -14,10 +14,16 @@ class IdleDetector extends EventEmitter {
} }
start() { start() {
console.log('Start idle detector');
this._scheduleNextCallback(); this._scheduleNextCallback();
} }
stop() { stop() {
console.log('Stop idle detector');
this._clearScheduledCallbacks();
}
_clearScheduledCallbacks() {
if (this.handle) { if (this.handle) {
cancelIdleCallback(this.handle); cancelIdleCallback(this.handle);
} }
@ -28,7 +34,7 @@ class IdleDetector extends EventEmitter {
} }
_scheduleNextCallback() { _scheduleNextCallback() {
this.stop(); this._clearScheduledCallbacks();
this.handle = window.requestIdleCallback((deadline) => { this.handle = window.requestIdleCallback((deadline) => {
const { didTimeout } = deadline; const { didTimeout } = deadline;
const timeRemaining = deadline.timeRemaining(); const timeRemaining = deadline.timeRemaining();

@ -237,7 +237,10 @@ const _processBatch = async ({ connection, upgradeMessageSchema } = {}) => {
await settings.deleteAttachmentMigrationLastProcessedIndex(connection); await settings.deleteAttachmentMigrationLastProcessedIndex(connection);
} }
const batchTotalDuration = Date.now() - fetchUnprocessedMessagesStartTime;
return { return {
batchTotalDuration,
done, done,
fetchDuration, fetchDuration,
lastProcessedIndex, lastProcessedIndex,

Loading…
Cancel
Save