Skip to content

Commit e0e6017

Browse files
authored
Merge pull request #1500 from Hirobreak/geoff
removing duplicated keys
2 parents cba5d1d + 613e5d7 commit e0e6017

File tree

9 files changed

+37
-14
lines changed

9 files changed

+37
-14
lines changed

electron_app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "criptext",
3-
"version": "0.30.0",
3+
"version": "0.30.1",
44
"author": {
55
"name": "Criptext Inc",
66
"email": "[email protected]",

electron_app/src/backup/exporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const start = async () => {
4141
try {
4242
await initDatabaseEncrypted({
4343
key: key,
44-
path: path.join(tempBackupDirectory, 'CriptextEncrypt.db'),
44+
dbpath: path.join(tempBackupDirectory, 'CriptextEncrypt.db'),
4545
sync: false
4646
});
4747
account = await Account().findOne({

electron_app/src/database/DBEmigrations/20200512111423_addBlockAllColumn.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,28 @@ const handleDuplicatedMessageIds = async (queryInterface, transaction) => {
4848
});
4949
await Email().destroy({
5050
where: {
51-
id: idsToDelete
51+
id: [].concat.apply([], idsToDelete)
52+
},
53+
transaction
54+
});
55+
};
56+
57+
const handleDuplicatedKeys = async (queryInterface, transaction) => {
58+
const query = `SELECT key, messageId, COUNT(*), GROUP_CONCAT(id) as 'ids' FROM ${
59+
Table.EMAIL
60+
} GROUP BY key HAVING COUNT(*) > 1 `;
61+
const [results] = await queryInterface.sequelize.query(query, {
62+
transaction
63+
});
64+
const idsToDelete = [];
65+
results.forEach(row => {
66+
const ids = row.ids.split(',');
67+
ids.shift();
68+
idsToDelete.push(ids);
69+
});
70+
await Email().destroy({
71+
where: {
72+
id: [].concat.apply([], idsToDelete)
5273
},
5374
transaction
5475
});
@@ -76,6 +97,7 @@ module.exports = {
7697

7798
try {
7899
await migrateBlockRemoteContent(queryInterface, Sequelize, transaction);
100+
await handleDuplicatedKeys(queryInterface, transaction);
79101
await handleDuplicatedMessageIds(queryInterface, transaction);
80102
await addUniqueIndexes(queryInterface, transaction);
81103
await transaction.commit();

electron_app/src/database/DBEmodel.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,23 @@ class Version extends Model {}
121121

122122
const getDB = () => sequelize;
123123

124-
const setConfiguration = (key, path, dialectPath) => {
124+
const setConfiguration = (key, path) => {
125125
sequelize = new Sequelize(null, null, key, {
126126
dialect: 'sqlite',
127-
dialectModulePath: dialectPath || '@journeyapps/sqlcipher',
127+
dialectModulePath: '@journeyapps/sqlcipher',
128128
storage: path || myDBEncryptPath(),
129129
logging: false,
130130
transactionType: 'IMMEDIATE'
131131
});
132132
};
133133

134134
const initDatabaseEncrypted = async (
135-
{ key, shouldReset, path, sync = true, dialectPath },
135+
{ key, shouldReset, dbpath, sync = true },
136136
migrationStartCallback
137137
) => {
138138
if (shouldReset) sequelize = undefined;
139139
if (sequelize) return;
140-
await setConfiguration(key, path, dialectPath);
140+
await setConfiguration(key, dbpath);
141141

142142
Account.init(
143143
{
@@ -607,10 +607,11 @@ const initDatabaseEncrypted = async (
607607

608608
try {
609609
const migrationPath = path.join(__dirname, '/DBEmigrations');
610+
const umzugPath = getUmzugPath(process.env.NODE_ENV);
610611
const migrator = new umzug({
611612
storage: 'json',
612613
storageOptions: {
613-
path: getUmzugPath(process.env.NODE_ENV)
614+
path: umzugPath
614615
},
615616
logging: false,
616617
upName: 'up',
@@ -634,7 +635,7 @@ const initDatabaseEncrypted = async (
634635
} catch (ex) {
635636
logger.error({
636637
message: 'Migrating Database',
637-
error: ex
638+
error: ex.toString()
638639
});
639640
}
640641
};

email_composer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "email_composer",
3-
"version": "0.30.0",
3+
"version": "0.30.1",
44
"private": true,
55
"dependencies": {
66
"@criptext/electron-better-ipc": "^0.7.0-rc1-0.2",

email_loading/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "email_loading",
3-
"version": "0.30.0",
3+
"version": "0.30.1",
44
"private": true,
55
"dependencies": {
66
"@criptext/electron-better-ipc": "^0.7.0-rc1-0.2",

email_login/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "email_login",
3-
"version": "0.30.0",
3+
"version": "0.30.1",
44
"private": true,
55
"dependencies": {
66
"@criptext/electron-better-ipc": "^0.7.0-rc1-0.2",

email_mailbox/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "email_mailbox",
3-
"version": "0.30.0",
3+
"version": "0.30.1",
44
"private": true,
55
"dependencies": {
66
"@criptext/electron-better-ipc": "^0.7.0-rc1-0.2",

email_pin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "email_pin",
3-
"version": "0.30.0",
3+
"version": "0.30.1",
44
"private": true,
55
"dependencies": {
66
"@criptext/electron-better-ipc": "^0.7.0-rc1-0.2",

0 commit comments

Comments
 (0)