Skip to content

Commit

Permalink
Merge pull request #1500 from Hirobreak/geoff
Browse files Browse the repository at this point in the history
removing duplicated keys
  • Loading branch information
javiteri95 committed Aug 3, 2020
2 parents cba5d1d + 613e5d7 commit e0e6017
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion electron_app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "criptext",
"version": "0.30.0",
"version": "0.30.1",
"author": {
"name": "Criptext Inc",
"email": "support@criptext.com",
Expand Down
2 changes: 1 addition & 1 deletion electron_app/src/backup/exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const start = async () => {
try {
await initDatabaseEncrypted({
key: key,
path: path.join(tempBackupDirectory, 'CriptextEncrypt.db'),
dbpath: path.join(tempBackupDirectory, 'CriptextEncrypt.db'),
sync: false
});
account = await Account().findOne({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,28 @@ const handleDuplicatedMessageIds = async (queryInterface, transaction) => {
});
await Email().destroy({
where: {
id: idsToDelete
id: [].concat.apply([], idsToDelete)
},
transaction
});
};

const handleDuplicatedKeys = async (queryInterface, transaction) => {
const query = `SELECT key, messageId, COUNT(*), GROUP_CONCAT(id) as 'ids' FROM ${
Table.EMAIL
} GROUP BY key HAVING COUNT(*) > 1 `;
const [results] = await queryInterface.sequelize.query(query, {
transaction
});
const idsToDelete = [];
results.forEach(row => {
const ids = row.ids.split(',');
ids.shift();
idsToDelete.push(ids);
});
await Email().destroy({
where: {
id: [].concat.apply([], idsToDelete)
},
transaction
});
Expand Down Expand Up @@ -76,6 +97,7 @@ module.exports = {

try {
await migrateBlockRemoteContent(queryInterface, Sequelize, transaction);
await handleDuplicatedKeys(queryInterface, transaction);
await handleDuplicatedMessageIds(queryInterface, transaction);
await addUniqueIndexes(queryInterface, transaction);
await transaction.commit();
Expand Down
13 changes: 7 additions & 6 deletions electron_app/src/database/DBEmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,23 @@ class Version extends Model {}

const getDB = () => sequelize;

const setConfiguration = (key, path, dialectPath) => {
const setConfiguration = (key, path) => {
sequelize = new Sequelize(null, null, key, {
dialect: 'sqlite',
dialectModulePath: dialectPath || '@journeyapps/sqlcipher',
dialectModulePath: '@journeyapps/sqlcipher',
storage: path || myDBEncryptPath(),
logging: false,
transactionType: 'IMMEDIATE'
});
};

const initDatabaseEncrypted = async (
{ key, shouldReset, path, sync = true, dialectPath },
{ key, shouldReset, dbpath, sync = true },
migrationStartCallback
) => {
if (shouldReset) sequelize = undefined;
if (sequelize) return;
await setConfiguration(key, path, dialectPath);
await setConfiguration(key, dbpath);

Account.init(
{
Expand Down Expand Up @@ -607,10 +607,11 @@ const initDatabaseEncrypted = async (

try {
const migrationPath = path.join(__dirname, '/DBEmigrations');
const umzugPath = getUmzugPath(process.env.NODE_ENV);
const migrator = new umzug({
storage: 'json',
storageOptions: {
path: getUmzugPath(process.env.NODE_ENV)
path: umzugPath
},
logging: false,
upName: 'up',
Expand All @@ -634,7 +635,7 @@ const initDatabaseEncrypted = async (
} catch (ex) {
logger.error({
message: 'Migrating Database',
error: ex
error: ex.toString()
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion email_composer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "email_composer",
"version": "0.30.0",
"version": "0.30.1",
"private": true,
"dependencies": {
"@criptext/electron-better-ipc": "^0.7.0-rc1-0.2",
Expand Down
2 changes: 1 addition & 1 deletion email_loading/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "email_loading",
"version": "0.30.0",
"version": "0.30.1",
"private": true,
"dependencies": {
"@criptext/electron-better-ipc": "^0.7.0-rc1-0.2",
Expand Down
2 changes: 1 addition & 1 deletion email_login/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "email_login",
"version": "0.30.0",
"version": "0.30.1",
"private": true,
"dependencies": {
"@criptext/electron-better-ipc": "^0.7.0-rc1-0.2",
Expand Down
2 changes: 1 addition & 1 deletion email_mailbox/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "email_mailbox",
"version": "0.30.0",
"version": "0.30.1",
"private": true,
"dependencies": {
"@criptext/electron-better-ipc": "^0.7.0-rc1-0.2",
Expand Down
2 changes: 1 addition & 1 deletion email_pin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "email_pin",
"version": "0.30.0",
"version": "0.30.1",
"private": true,
"dependencies": {
"@criptext/electron-better-ipc": "^0.7.0-rc1-0.2",
Expand Down

0 comments on commit e0e6017

Please sign in to comment.