Background message migration: Process just one batch at a time
This commit is contained in:
parent
2105ee13f1
commit
b9ba732724
1 changed files with 40 additions and 20 deletions
|
@ -850,35 +850,55 @@ export async function startApp(): Promise<void> {
|
||||||
setAppLoadingScreenMessage(window.i18n('loading'), window.i18n);
|
setAppLoadingScreenMessage(window.i18n('loading'), window.i18n);
|
||||||
|
|
||||||
let isMigrationWithIndexComplete = false;
|
let isMigrationWithIndexComplete = false;
|
||||||
|
let isIdleTaskProcessing = false;
|
||||||
log.info(
|
log.info(
|
||||||
`Starting background data migration. Target version: ${Message.CURRENT_SCHEMA_VERSION}`
|
`Starting background data migration. Target version: ${Message.CURRENT_SCHEMA_VERSION}`
|
||||||
);
|
);
|
||||||
idleDetector.on('idle', async () => {
|
idleDetector.on('idle', async () => {
|
||||||
const NUM_MESSAGES_PER_BATCH = 100;
|
const NUM_MESSAGES_PER_BATCH = 25;
|
||||||
const BATCH_DELAY = 5 * durations.SECOND;
|
const BATCH_DELAY = 10 * durations.SECOND;
|
||||||
|
|
||||||
if (!isMigrationWithIndexComplete) {
|
if (isIdleTaskProcessing) {
|
||||||
const batchWithIndex = await migrateMessageData({
|
log.warn(
|
||||||
numMessagesPerBatch: NUM_MESSAGES_PER_BATCH,
|
'idleDetector/idle: previous batch incomplete, not starting another'
|
||||||
upgradeMessageSchema,
|
);
|
||||||
getMessagesNeedingUpgrade:
|
return;
|
||||||
window.Signal.Data.getMessagesNeedingUpgrade,
|
|
||||||
saveMessages: window.Signal.Data.saveMessages,
|
|
||||||
});
|
|
||||||
log.info('Upgrade message schema (with index):', batchWithIndex);
|
|
||||||
isMigrationWithIndexComplete = batchWithIndex.done;
|
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
isIdleTaskProcessing = true;
|
||||||
|
|
||||||
idleDetector.stop();
|
if (!isMigrationWithIndexComplete) {
|
||||||
|
log.warn(
|
||||||
|
`idleDetector/idle: fetching at most ${NUM_MESSAGES_PER_BATCH} for migration`
|
||||||
|
);
|
||||||
|
const batchWithIndex = await migrateMessageData({
|
||||||
|
numMessagesPerBatch: NUM_MESSAGES_PER_BATCH,
|
||||||
|
upgradeMessageSchema,
|
||||||
|
getMessagesNeedingUpgrade:
|
||||||
|
window.Signal.Data.getMessagesNeedingUpgrade,
|
||||||
|
saveMessages: window.Signal.Data.saveMessages,
|
||||||
|
});
|
||||||
|
log.info('idleDetector/idle: Upgraded messages:', batchWithIndex);
|
||||||
|
isMigrationWithIndexComplete = batchWithIndex.done;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
idleDetector.stop();
|
||||||
|
|
||||||
if (isMigrationWithIndexComplete) {
|
if (isMigrationWithIndexComplete) {
|
||||||
log.info('Background migration complete. Stopping idle detector.');
|
log.info(
|
||||||
} else {
|
'idleDetector/idle: Background migration complete. Stopping.'
|
||||||
log.info('Background migration not complete. Pausing idle detector.');
|
);
|
||||||
|
} else {
|
||||||
|
log.info(
|
||||||
|
`idleDetector/idle: Background migration not complete. Pausing for ${BATCH_DELAY}ms.`
|
||||||
|
);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
idleDetector.start();
|
idleDetector.start();
|
||||||
}, BATCH_DELAY);
|
}, BATCH_DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
isIdleTaskProcessing = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue