From af3102441df76724f050dfb8e8816c17056d3a9f Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 26 Oct 2018 17:54:16 -0600 Subject: [PATCH] ensure device updates are persisted Previously we'd skip saves when latest was the same instance as self, which was *at least* occurring during the 404 handler for prekey fetching while message sending. In practice this was cached, so it would be one wasted request per recipient per launch. --- .../src/Contacts/SignalRecipient.m | 35 +++++-------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/SignalServiceKit/src/Contacts/SignalRecipient.m b/SignalServiceKit/src/Contacts/SignalRecipient.m index 4ceda6a2e..170a1c7ef 100644 --- a/SignalServiceKit/src/Contacts/SignalRecipient.m +++ b/SignalServiceKit/src/Contacts/SignalRecipient.m @@ -161,19 +161,11 @@ NS_ASSUME_NONNULL_BEGIN { OWSAssertDebug(transaction); OWSAssertDebug(devices.count > 0); - - [self addDevices:devices]; - - SignalRecipient *latest = [SignalRecipient markRecipientAsRegisteredAndGet:self.recipientId - transaction:transaction]; - - if ([devices isSubsetOfSet:latest.devices.set]) { - return; - } - OWSLogDebug(@"adding devices: %@, to recipient: %@", devices, latest.recipientId); + OWSLogDebug(@"adding devices: %@, to recipient: %@", devices, self); - [latest addDevices:devices]; - [latest saveWithTransaction_internal:transaction]; + [self reloadWithTransaction:transaction]; + [self addDevices:devices]; + [self saveWithTransaction_internal:transaction]; } - (void)removeDevicesFromRecipient:(NSSet *)devices transaction:(YapDatabaseReadWriteTransaction *)transaction @@ -181,23 +173,12 @@ NS_ASSUME_NONNULL_BEGIN OWSAssertDebug(transaction); OWSAssertDebug(devices.count > 0); + OWSLogDebug(@"removing devices: %@, from registered recipient: %@", devices, self); + [self reloadWithTransaction:transaction]; [self removeDevices:devices]; - SignalRecipient *_Nullable latest = - [SignalRecipient registeredRecipientForRecipientId:self.recipientId transaction:transaction]; - - if (!latest) { - return; - } - if (![devices intersectsSet:latest.devices.set]) { - return; - } - OWSLogDebug(@"removing devices: %@, from registered recipient: %@", devices, latest.recipientId); - - [latest removeDevices:devices]; - - if (latest.devices.count > 0) { - [latest saveWithTransaction_internal:transaction]; + if (self.devices.count > 0) { + [self saveWithTransaction_internal:transaction]; } else { [SignalRecipient removeUnregisteredRecipient:self.recipientId transaction:transaction]; }