Optimize key removal during verification

This commit is contained in:
Tankred Hase 2017-08-25 16:20:33 +08:00 committed by GitHub
parent 77fc0fd195
commit b93db84c6a
1 changed files with 2 additions and 4 deletions

View File

@ -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)));
}
/**