mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
94e85dc09e
refs https://ghost.slack.com/archives/C02G9E68C/p1670960248186789
This reverts a change that was made here:
f4fdb4fa6c (r93071549)
,
but it still moved the original code to a new location in the
LastSeenAtUpdater
It includes a new E2E test to make sure timezones are supported
correctly.
- By not using Bookshelf, we no longer fire webhook calls
- By not using the member repository, we don't fetch and update the
member model and the labels relation in a forUpdate transaction, which
caused deadlock issues on the labels/members_labels tables which were
hard to resolve. Until now I was unable to find the other conflicting
transaction that caused this deadlock. Moving to raw knex (instead of
Bookshelf) and only updating the last_updated_at column should remove
the deadlock issue.
This removed the test for the email service wrapper, since it started
failing for an unknown reason and the test didn't make much sense (was
added earlier only to bump test threshold).
47 lines
1.9 KiB
JavaScript
47 lines
1.9 KiB
JavaScript
require('should');
|
|
const {agentProvider, fixtureManager, mockManager} = require('../../utils/e2e-framework');
|
|
const models = require('../../../core/server/models');
|
|
const assert = require('assert');
|
|
let agent;
|
|
|
|
describe('Last Seen At Updater', function () {
|
|
before(async function () {
|
|
agent = await agentProvider.getAdminAPIAgent();
|
|
await fixtureManager.init('newsletters', 'members:newsletters');
|
|
await agent.loginAsOwner();
|
|
});
|
|
|
|
it('updateLastSeenAtWithoutKnownLastSeen', async function () {
|
|
const membersEvents = require('../../../core/server/services/members-events');
|
|
|
|
// Fire lots of EmailOpenedEvent for the same
|
|
const memberId = fixtureManager.get('members', 0).id;
|
|
|
|
const firstDate = new Date(Date.UTC(2099, 11, 31, 21, 0, 0, 0));
|
|
// In UTC this is 2099-12-31 21:00:00
|
|
// In CET this is 2099-12-31 22:00:00
|
|
|
|
const secondDate = new Date(Date.UTC(2099, 11, 31, 22, 0, 0, 0));
|
|
// In UTC this is 2099-12-31 22:00:00
|
|
// In CET this is 2099-12-31 23:00:00
|
|
|
|
const newDay = new Date(Date.UTC(2099, 11, 31, 23, 0, 0, 0));
|
|
// In UTC this is 2099-12-31 23:00:00
|
|
// In CET this is 2100-01-01 00:00:00
|
|
|
|
async function assertLastSeen(date) {
|
|
const member = await models.Member.findOne({id: memberId}, {require: true});
|
|
assert.equal(member.get('last_seen_at').getTime(), date.getTime());
|
|
}
|
|
|
|
mockManager.mockSetting('timezone', 'CET');
|
|
|
|
await membersEvents.lastSeenAtUpdater.updateLastSeenAtWithoutKnownLastSeen(memberId, firstDate);
|
|
await assertLastSeen(firstDate);
|
|
await membersEvents.lastSeenAtUpdater.updateLastSeenAtWithoutKnownLastSeen(memberId, secondDate);
|
|
await assertLastSeen(firstDate); // not changed
|
|
await membersEvents.lastSeenAtUpdater.updateLastSeenAtWithoutKnownLastSeen(memberId, newDay);
|
|
await assertLastSeen(newDay); // changed
|
|
});
|
|
});
|