From f5daf91e8d46687e40f8844d6cdf68f2fe85e8f6 Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Wed, 6 Mar 2024 11:54:32 +0200 Subject: [PATCH] fix(fetch): Allow to set the fetch batch size limit with a cli argument --- lib/consts.js | 2 +- lib/mailbox.js | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/consts.js b/lib/consts.js index 43fc6c89..1a535188 100644 --- a/lib/consts.js +++ b/lib/consts.js @@ -167,7 +167,7 @@ module.exports = { FETCH_RETRY_INTERVAL: 1000, FETCH_RETRY_EXPONENTIAL: 2, FETCH_RETRY_MAX: 60 * 1000, - MAX_FETCH_RANGE: Number((process.env.EENGINE_MAX_FETCH_RANGE || '').toString().trim()) || 1000, + DEFAULT_FETCH_BATCH_SIZE: 1000, generateWebhookTable() { let entries = []; diff --git a/lib/mailbox.js b/lib/mailbox.js index ee3b78c4..2e4a35d6 100644 --- a/lib/mailbox.js +++ b/lib/mailbox.js @@ -9,12 +9,14 @@ const { download, filterEmptyObjectValues, validUidValidity, - calculateFetchBackoff + calculateFetchBackoff, + readEnvValue } = require('./tools'); const msgpack = require('msgpack5')(); const he = require('he'); const libmime = require('libmime'); const settings = require('./settings'); +const config = require('wild-config'); const { bounceDetect } = require('./bounce-detect'); const { arfDetect } = require('./arf-detect'); const appendList = require('./append-list'); @@ -38,9 +40,11 @@ const { REDIS_PREFIX, MAX_INLINE_ATTACHMENT_SIZE, MAX_ALLOWED_DOWNLOAD_SIZE, - MAX_FETCH_RANGE + DEFAULT_FETCH_BATCH_SIZE } = require('./consts'); +const FETCH_BATCH_SIZE = Number(readEnvValue('EENGINE_FETCH_BATCH_SIZE') || config.service.fetchBatchSize) || DEFAULT_FETCH_BATCH_SIZE; + // Do not check for flag updates using full sync more often than this value const FULL_SYNC_DELAY = 30 * 60 * 1000; @@ -54,7 +58,7 @@ function getFetchRange(totalMessages, lastRange) { if (startUid > totalMessages) { return false; } - let endMarker = startUid + MAX_FETCH_RANGE - 1; + let endMarker = startUid + FETCH_BATCH_SIZE - 1; if (endMarker >= totalMessages) { endMarker = '*'; }