mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
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:
parent
3ded0bbee8
commit
89ababb71f
2 changed files with 12 additions and 5 deletions
|
@ -25,6 +25,13 @@ describe('EmailEventStorage', function () {
|
||||||
let membersService;
|
let membersService;
|
||||||
|
|
||||||
before(async function () {
|
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();
|
agent = await agentProvider.getAdminAPIAgent();
|
||||||
await fixtureManager.init('newsletters', 'members:newsletters', 'members:emails');
|
await fixtureManager.init('newsletters', 'members:newsletters', 'members:emails');
|
||||||
await agent.loginAsOwner();
|
await agent.loginAsOwner();
|
||||||
|
|
|
@ -76,10 +76,10 @@ module.exports = class EmailAnalyticsService {
|
||||||
const begin = await this.getLastEventTimestamp();
|
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
|
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
|
// Skip for now
|
||||||
logging.info('[EmailAnalytics] Skipping fetchLatest because end (' + end + ') is before begin (' + begin + ')');
|
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
|
// 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
|
// Skip for now
|
||||||
logging.info('[EmailAnalytics] Skipping fetchMissing because end (' + end + ') is before begin (' + begin + ')');
|
logging.info('[EmailAnalytics] Skipping fetchMissing because end (' + end + ') is before begin (' + begin + ')');
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -178,9 +178,9 @@ module.exports = class EmailAnalyticsService {
|
||||||
begin = this.#fetchScheduledData.lastEventTimestamp;
|
begin = this.#fetchScheduledData.lastEventTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (end < begin) {
|
if (end <= begin) {
|
||||||
// Skip for now
|
// 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;
|
this.#fetchScheduledData = null;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue