From c94c4bc7e0eb59aa3929b4ec9c8decc510d2b24d Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 9 Jul 2015 12:47:16 -0700 Subject: [PATCH] Remove redundant identity key updates We were re-saving the key when it did not conflict with the exisiting value. --- js/axolotl_store.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/js/axolotl_store.js b/js/axolotl_store.js index 90f3706dbc3..bfcdee07d58 100644 --- a/js/axolotl_store.js +++ b/js/axolotl_store.js @@ -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"); + } + } }); }); },