From c64aeec36a0581675097ac335572634b2b3b839f Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Tue, 4 Aug 2026 10:07:35 -0400 Subject: [PATCH] Add a public "update account with additional write items" method --- .../storage/AccountsManager.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java index 2f529d041..4e8e4201b 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java @@ -36,6 +36,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Base64; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -961,6 +962,17 @@ public class AccountsManager extends RedisPubSubAdapter implemen }); } + public Account update(final UUID accountIdentifier, + final Consumer updater, + final Collection additionalWriteItems) { + + return update(accountIdentifier, a -> { + updater.accept(a); + // assume that all updaters passed to the public method actually modify the account + return true; + }, additionalWriteItems); + } + /// Using a pessimistic lock, updates the current profile version to `newVersion` if `currentProfileVersion` matches /// `expectedCurrentVersion`. The caller may provide a supplementary `Consumer` for additional updates /// @@ -1021,12 +1033,27 @@ public class AccountsManager extends RedisPubSubAdapter implemen * @param accountIdentifier identifier of account to update * @param updater must return {@code true} if the account was actually updated */ - private Account update(UUID accountIdentifier, Function updater) { + private Account update(final UUID accountIdentifier, final Function updater) { + return update(accountIdentifier, updater, Collections.emptyList()); + } + + /** + * @param accountIdentifier identifier of account to update + * @param updater must return {@code true} if the account was actually updated + * @param additionalWriteItems additional write items to include in a transactional update + */ + private Account update(final UUID accountIdentifier, + final Function updater, + final Collection additionalWriteItems) { + + final ThrowingConsumer persister = additionalWriteItems.isEmpty() + ? accounts::update + : account -> accounts.updateTransactionally(account, additionalWriteItems); return updateTimer.record(() -> { final Account updatedAccount = updateWithRetries(updater, - accounts::update, + persister, () -> accounts.getByAccountIdentifier(accountIdentifier).orElseThrow(), AccountChangeValidator.GENERAL_CHANGE_VALIDATOR);