From b93db84c6a1c2fe39ac0ca74f0a6ff91d708e5e8 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Fri, 25 Aug 2017 16:20:33 +0800 Subject: [PATCH] Optimize key removal during verification --- src/service/public-key.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/service/public-key.js b/src/service/public-key.js index 5c61eaf..4f78949 100644 --- a/src/service/public-key.js +++ b/src/service/public-key.js @@ -152,12 +152,10 @@ class PublicKey { } async _removeKeysWithSameEmail({keyId, userIds}, nonce) { - const {email} = userIds.find(uid => uid.nonce === nonce); - const keys = await this._mongo.list({ + return this._mongo.remove({ keyId: {$ne: keyId}, - 'userIds.email': email + 'userIds.email': userIds.find(u => u.nonce === nonce).email }, DB_TYPE); - await Promise.all(keys.map(({_id}) => this._mongo.remove({_id}, DB_TYPE))); } /**