Updated email event fetching to stop when begin and end are the same (#16326)

no issue

Optimization that makes sure we stop fetching when it is no longer
needed.
This commit is contained in:
Simon Backx 2023-02-23 15:44:01 +01:00 committed by GitHub
parent 3ded0bbee8
commit 89ababb71f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View File

@ -25,6 +25,13 @@ describe('EmailEventStorage', function () {
let membersService;
before(async function () {
// Stub queries before boot
const queries = require('../../../../core/server/services/email-analytics/lib/queries');
sinon.stub(queries, 'getLastSeenEventTimestamp').callsFake(async function () {
// This is required because otherwise the last event timestamp will be now, and that is too close to NOW to start fetching new events
return new Date(2000, 0, 1);
});
agent = await agentProvider.getAdminAPIAgent();
await fixtureManager.init('newsletters', 'members:newsletters', 'members:emails');
await agent.loginAsOwner();

View File

@ -76,10 +76,10 @@ module.exports = class EmailAnalyticsService {
const begin = await this.getLastEventTimestamp();
const end = new Date(Date.now() - FETCH_LATEST_END_MARGIN_MS); // ALways stop at x minutes ago to give Mailgun a bit more time to stabilize storage
if (end < begin) {
if (end <= begin) {
// Skip for now
logging.info('[EmailAnalytics] Skipping fetchLatest because end (' + end + ') is before begin (' + begin + ')');
//return 0;
return 0;
}
// Create the fetch data object if it doesn't exist yet
@ -109,7 +109,7 @@ module.exports = class EmailAnalyticsService {
)
);
if (end < begin) {
if (end <= begin) {
// Skip for now
logging.info('[EmailAnalytics] Skipping fetchMissing because end (' + end + ') is before begin (' + begin + ')');
return 0;
@ -178,9 +178,9 @@ module.exports = class EmailAnalyticsService {
begin = this.#fetchScheduledData.lastEventTimestamp;
}
if (end < begin) {
if (end <= begin) {
// Skip for now
logging.info('[EmailAnalytics] Skipping fetchScheduled because end is before begin');
logging.info('[EmailAnalytics] Ending fetchScheduled because end is before begin');
this.#fetchScheduledData = null;
return 0;
}