perf: move encryption/decryption to a separate thread

This commit is contained in:
Dragory 2021-10-09 14:21:23 +03:00
parent 0b337a13a4
commit b7c7e002eb
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
16 changed files with 310 additions and 147 deletions

View file

@ -9,7 +9,7 @@ export class EncryptExistingMessages1600283341726 implements MigrationInterface
// 2. Encrypt all permanent messages
const messages = await queryRunner.query("SELECT id, data FROM messages");
for (const message of messages) {
const encryptedData = encrypt(message.data);
const encryptedData = await encrypt(message.data);
await queryRunner.query("UPDATE messages SET data = ? WHERE id = ?", [encryptedData, message.id]);
}
}
@ -18,7 +18,7 @@ export class EncryptExistingMessages1600283341726 implements MigrationInterface
// Decrypt all messages
const messages = await queryRunner.query("SELECT id, data FROM messages");
for (const message of messages) {
const decryptedData = decrypt(message.data);
const decryptedData = await decrypt(message.data);
await queryRunner.query("UPDATE messages SET data = ? WHERE id = ?", [decryptedData, message.id]);
}
}

View file

@ -5,7 +5,7 @@ export class EncryptArchives1600285077890 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<any> {
const archives = await queryRunner.query("SELECT id, body FROM archives");
for (const archive of archives) {
const encryptedBody = encrypt(archive.body);
const encryptedBody = await encrypt(archive.body);
await queryRunner.query("UPDATE archives SET body = ? WHERE id = ?", [encryptedBody, archive.id]);
}
}
@ -13,7 +13,7 @@ export class EncryptArchives1600285077890 implements MigrationInterface {
public async down(queryRunner: QueryRunner): Promise<any> {
const archives = await queryRunner.query("SELECT id, body FROM archives");
for (const archive of archives) {
const decryptedBody = decrypt(archive.body);
const decryptedBody = await decrypt(archive.body);
await queryRunner.query("UPDATE archives SET body = ? WHERE id = ?", [decryptedBody, archive.id]);
}
}