Mailspring/packages/client-sync/main.es6

27 lines
873 B
Text
Raw Normal View History

/* eslint global-require: 0 */
import Sequelize from 'sequelize'; // eslint-disable-line
import {ComponentRegistry} from 'nylas-exports'
import {createLogger} from './src/shared/logger'
import shimSequelize from './src/shared/shim-sequelize'
[client-sync] Prevent duplicate accounts and sync workers Summary: After https://github.com/nylas/nylas-mail-all/commit/008cb4c, the shape of account.connectionSettings changed, which means that ids for accounts will also change, given that they are based on the connection settings (see Account.hash()). This is fine in most cases, except for accounts that were running on a version of Nylas Mail before 008cb4c, then upgraded to a version after 008cb4c, and then re-authed their account. In this scenario, re-authing the account will create a second account with a different `id` but with the same email address, along with an extra sequelize database, and will start a second SyncWorker for the same account. App-side, the `AccountStore` will correctly overwrite the first account, so users would correctly see just 1 account in the sidebar. However, given that 2 SyncWorkers would be running for the same account, message ids would collide in edgehill.db and this would cause threads to disappear from the ui as if they were being deleted. To fix this, we need to do 2 things: - Upon app start, we remove any duplicate accounts that might have been created due to this bug before starting any sync workers - If we detect that we are going to create a duplicate account upon auth success, we delete the old account first. This will effectively cause sync to restart for the account. Test Plan: Verified problem: Checked out a commit before 008cb4c, authed an account, checked out master, re-authed account, verified that duplicate accounts are created. Then test 2 scenarios: - With duplicate accounts present, checked out this commit, verified that duplicate account would be removed and sync would function normally. - With an account authed on a build before 008cb4c, checked out this commit, re-authed the account, and verified that duplicate account wouldn't be created Reviewers: mark, halla, khamidou, spang Reviewed By: spang Subscribers: tomasz Differential Revision: https://phab.nylas.com/D4425
2017-04-14 12:46:38 +08:00
import {removeDuplicateAccountsWithOldSettings} from './src/shared/dedupe-accounts'
2016-11-23 07:13:28 +08:00
[client-sync] Prevent duplicate accounts and sync workers Summary: After https://github.com/nylas/nylas-mail-all/commit/008cb4c, the shape of account.connectionSettings changed, which means that ids for accounts will also change, given that they are based on the connection settings (see Account.hash()). This is fine in most cases, except for accounts that were running on a version of Nylas Mail before 008cb4c, then upgraded to a version after 008cb4c, and then re-authed their account. In this scenario, re-authing the account will create a second account with a different `id` but with the same email address, along with an extra sequelize database, and will start a second SyncWorker for the same account. App-side, the `AccountStore` will correctly overwrite the first account, so users would correctly see just 1 account in the sidebar. However, given that 2 SyncWorkers would be running for the same account, message ids would collide in edgehill.db and this would cause threads to disappear from the ui as if they were being deleted. To fix this, we need to do 2 things: - Upon app start, we remove any duplicate accounts that might have been created due to this bug before starting any sync workers - If we detect that we are going to create a duplicate account upon auth success, we delete the old account first. This will effectively cause sync to restart for the account. Test Plan: Verified problem: Checked out a commit before 008cb4c, authed an account, checked out master, re-authed account, verified that duplicate accounts are created. Then test 2 scenarios: - With duplicate accounts present, checked out this commit, verified that duplicate account would be removed and sync would function normally. - With an account authed on a build before 008cb4c, checked out this commit, re-authed the account, and verified that duplicate account wouldn't be created Reviewers: mark, halla, khamidou, spang Reviewed By: spang Subscribers: tomasz Differential Revision: https://phab.nylas.com/D4425
2017-04-14 12:46:38 +08:00
export async function activate() {
shimSequelize(Sequelize);
global.Logger = createLogger()
require('./src/local-api');
[client-sync] Prevent duplicate accounts and sync workers Summary: After https://github.com/nylas/nylas-mail-all/commit/008cb4c, the shape of account.connectionSettings changed, which means that ids for accounts will also change, given that they are based on the connection settings (see Account.hash()). This is fine in most cases, except for accounts that were running on a version of Nylas Mail before 008cb4c, then upgraded to a version after 008cb4c, and then re-authed their account. In this scenario, re-authing the account will create a second account with a different `id` but with the same email address, along with an extra sequelize database, and will start a second SyncWorker for the same account. App-side, the `AccountStore` will correctly overwrite the first account, so users would correctly see just 1 account in the sidebar. However, given that 2 SyncWorkers would be running for the same account, message ids would collide in edgehill.db and this would cause threads to disappear from the ui as if they were being deleted. To fix this, we need to do 2 things: - Upon app start, we remove any duplicate accounts that might have been created due to this bug before starting any sync workers - If we detect that we are going to create a duplicate account upon auth success, we delete the old account first. This will effectively cause sync to restart for the account. Test Plan: Verified problem: Checked out a commit before 008cb4c, authed an account, checked out master, re-authed account, verified that duplicate accounts are created. Then test 2 scenarios: - With duplicate accounts present, checked out this commit, verified that duplicate account would be removed and sync would function normally. - With an account authed on a build before 008cb4c, checked out this commit, re-authed the account, and verified that duplicate account wouldn't be created Reviewers: mark, halla, khamidou, spang Reviewed By: spang Subscribers: tomasz Differential Revision: https://phab.nylas.com/D4425
2017-04-14 12:46:38 +08:00
// NOTE: See https://phab.nylas.com/D4425 for explanation of why this check
// is necessary
// TODO remove this check after it no longer affects users
await removeDuplicateAccountsWithOldSettings()
require('./src/local-sync-worker');
const Root = require('./src/local-sync-dashboard/root').default;
ComponentRegistry.register(Root, {role: 'Developer:LocalSyncUI'});
2016-11-23 04:25:27 +08:00
}
export function deactivate() {
}