mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-25 01:36:06 +08:00
Summary: Sync operations are mostly bound by I/O and the imap connection. What we believe that is mostly affecting cpu and battery life is that node’s event loop is being hosed with cpu intensive message processing operations. To alleviate this, we do a few things: - Restore a global message processing queue to process messages serially and meter cpu usage (message processing continues to be a fire and forget call from within sync operations) - Move actual cpu intensive work to the message processing queue, i.e. `MessageFactory.parseFromImap` - Keep track of message processing queue length, and skip sync operations if queue is too big to prevent massive memory consumption This commit also renames the package from new-message-processor to message-processor, given that now it processes both new and existing messages, and we like to minimize confusion. Test Plan: manual Reviewers: spang, khamidou, evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D3602
80 lines
2.8 KiB
JavaScript
80 lines
2.8 KiB
JavaScript
/* eslint global-require: 0 */
|
|
/* eslint import/no-dynamic-require: 0 */
|
|
const detectThread = require('../src/message-processor/detect-thread');
|
|
const LocalDatabaseConnector = require('../src/shared/local-database-connector');
|
|
|
|
const {FIXTURES_PATH, ACCOUNT_ID} = require('./helpers')
|
|
|
|
function messagesFromFixture({Message}, folder, name) {
|
|
const {A, B} = require(`${FIXTURES_PATH}/Threading/${name}`)
|
|
|
|
const msgA = Message.build(A);
|
|
msgA.folder = folder;
|
|
msgA.labels = [];
|
|
|
|
const msgB = Message.build(B);
|
|
msgB.folder = folder;
|
|
msgB.labels = [];
|
|
|
|
return {msgA, msgB};
|
|
}
|
|
|
|
xdescribe('threading', function threadingSpecs() {
|
|
beforeEach(() => {
|
|
waitsForPromise({timeout: 1000}, async () => {
|
|
await LocalDatabaseConnector.ensureAccountDatabase(ACCOUNT_ID);
|
|
this.db = await LocalDatabaseConnector.forAccount(ACCOUNT_ID);
|
|
this.folder = await this.db.Folder.create({
|
|
id: 'test-folder-id',
|
|
accountId: ACCOUNT_ID,
|
|
version: 1,
|
|
name: 'Test Folder',
|
|
role: null,
|
|
});
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
LocalDatabaseConnector.destroyAccountDatabase(ACCOUNT_ID)
|
|
})
|
|
|
|
describe("when remote thread ids are present", () => {
|
|
it('threads emails with the same gthreadid', () => {
|
|
waitsForPromise(async () => {
|
|
const {msgA, msgB} = messagesFromFixture(this.db, this.folder, 'remote-thread-id-yes');
|
|
const threadA = await detectThread({db: this.db, message: msgA});
|
|
const threadB = await detectThread({db: this.db, message: msgB});
|
|
expect(threadB.id).toEqual(threadA.id);
|
|
});
|
|
});
|
|
|
|
it('does not thread other emails', () => {
|
|
waitsForPromise(async () => {
|
|
const {msgA, msgB} = messagesFromFixture(this.db, this.folder, 'remote-thread-id-no');
|
|
const threadA = await detectThread({db: this.db, message: msgA});
|
|
const threadB = await detectThread({db: this.db, message: msgB});
|
|
expect(threadB.id).not.toEqual(threadA.id);
|
|
});
|
|
});
|
|
});
|
|
describe("when subject matching", () => {
|
|
it('threads emails with the same subject', () => {
|
|
waitsForPromise(async () => {
|
|
const {msgA, msgB} = messagesFromFixture(this.db, this.folder, 'subject-matching-yes');
|
|
const threadA = await detectThread({db: this.db, message: msgA});
|
|
const threadB = await detectThread({db: this.db, message: msgB});
|
|
expect(threadB.id).toEqual(threadA.id);
|
|
});
|
|
});
|
|
|
|
it('does not thread other emails', () => {
|
|
waitsForPromise(async () => {
|
|
const {msgA, msgB} = messagesFromFixture(this.db, this.folder, 'subject-matching-no');
|
|
const threadA = await detectThread({db: this.db, message: msgA});
|
|
const threadB = await detectThread({db: this.db, message: msgB});
|
|
expect(threadB.id).not.toEqual(threadA.id);
|
|
});
|
|
});
|
|
});
|
|
});
|