Improve termination condition
This commit is contained in:
parent
5b1a0c45df
commit
38ac9972e8
1 changed files with 3 additions and 2 deletions
|
@ -192,11 +192,12 @@ const _processBatch = async ({ connection, upgradeMessageSchema } = {}) => {
|
||||||
const lastProcessedIndex =
|
const lastProcessedIndex =
|
||||||
await settings.getAttachmentMigrationLastProcessedIndex(connection);
|
await settings.getAttachmentMigrationLastProcessedIndex(connection);
|
||||||
|
|
||||||
|
const count = NUM_MESSAGES_PER_BATCH;
|
||||||
const fetchUnprocessedMessagesStartTime = Date.now();
|
const fetchUnprocessedMessagesStartTime = Date.now();
|
||||||
const unprocessedMessages =
|
const unprocessedMessages =
|
||||||
await _dangerouslyFetchMessagesRequiringSchemaUpgradeWithoutIndex({
|
await _dangerouslyFetchMessagesRequiringSchemaUpgradeWithoutIndex({
|
||||||
connection,
|
connection,
|
||||||
count: NUM_MESSAGES_PER_BATCH,
|
count,
|
||||||
lastIndex: lastProcessedIndex,
|
lastIndex: lastProcessedIndex,
|
||||||
});
|
});
|
||||||
const fetchDuration = Date.now() - fetchUnprocessedMessagesStartTime;
|
const fetchDuration = Date.now() - fetchUnprocessedMessagesStartTime;
|
||||||
|
@ -214,7 +215,7 @@ const _processBatch = async ({ connection, upgradeMessageSchema } = {}) => {
|
||||||
const saveDuration = Date.now() - saveMessagesStartTime;
|
const saveDuration = Date.now() - saveMessagesStartTime;
|
||||||
|
|
||||||
const numMessagesProcessed = upgradedMessages.length;
|
const numMessagesProcessed = upgradedMessages.length;
|
||||||
const done = numMessagesProcessed === 0;
|
const done = numMessagesProcessed < count;
|
||||||
const lastMessage = last(upgradedMessages);
|
const lastMessage = last(upgradedMessages);
|
||||||
const newLastProcessedIndex = lastMessage ? lastMessage.id : null;
|
const newLastProcessedIndex = lastMessage ? lastMessage.id : null;
|
||||||
if (!done) {
|
if (!done) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue