Remove redundant identity key updates

We were re-saving the key when it did not conflict with the exisiting
value.
This commit is contained in:
lilia 2015-07-09 12:47:16 -07:00
parent 2e272b6894
commit c94c4bc7e0

View file

@ -263,9 +263,17 @@
var identityKey = new IdentityKey({id: number});
identityKey.fetch().always(function() {
var oldpublicKey = identityKey.get('publicKey');
if (oldpublicKey && !equalArrayBuffers(oldpublicKey, publicKey))
throw new Error("Attempted to overwrite a different identity key");
identityKey.save({publicKey: publicKey}).then(resolve);
if (!oldpublicKey) {
// Lookup failed, or the current key was removed, so save this one.
identityKey.save({publicKey: publicKey}).then(resolve);
} else {
// Key exists, if it matches do nothing, else throw
if (equalArrayBuffers(oldpublicKey, publicKey)) {
resolve();
} else {
throw new Error("Attempted to overwrite a different identity key");
}
}
});
});
},