From 822092044b741c31ed9bfa9d2c3d969198687cc3 Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Wed, 31 Jul 2024 10:19:13 -0400 Subject: [PATCH] Add a method to check for the presence of persisted messages, skipping the cache --- ...yIdleDevicesWithoutMessagesPushNotificationExperiment.java | 4 ++-- .../whispersystems/textsecuregcm/storage/MessagesManager.java | 4 ++++ ...eDevicesWithoutMessagesPushNotificationExperimentTest.java | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/experiment/NotifyIdleDevicesWithoutMessagesPushNotificationExperiment.java b/service/src/main/java/org/whispersystems/textsecuregcm/experiment/NotifyIdleDevicesWithoutMessagesPushNotificationExperiment.java index aeb129dd4..500509e5b 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/experiment/NotifyIdleDevicesWithoutMessagesPushNotificationExperiment.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/experiment/NotifyIdleDevicesWithoutMessagesPushNotificationExperiment.java @@ -64,8 +64,8 @@ public CompletableFuture isDeviceEligible(final Account account, final return CompletableFuture.completedFuture(false); } - return messagesManager.mayHaveMessages(account.getIdentifier(IdentityType.ACI), device) - .thenApply(mayHaveMessages -> !mayHaveMessages); + return messagesManager.mayHavePersistedMessages(account.getIdentifier(IdentityType.ACI), device) + .thenApply(mayHavePersistedMessages -> !mayHavePersistedMessages); } @VisibleForTesting diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/MessagesManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/MessagesManager.java index 414512290..2c7cc4011 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/MessagesManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/MessagesManager.java @@ -67,6 +67,10 @@ public void insert(UUID destinationUuid, byte destinationDevice, Envelope messag } } + public CompletableFuture mayHavePersistedMessages(final UUID destinationUuid, final Device destinationDevice) { + return messagesDynamoDb.mayHaveMessages(destinationUuid, destinationDevice); + } + public CompletableFuture mayHaveMessages(final UUID destinationUuid, final Device destinationDevice) { return messagesCache.hasMessagesAsync(destinationUuid, destinationDevice.getId()) .thenCombine(messagesDynamoDb.mayHaveMessages(destinationUuid, destinationDevice), diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/experiment/NotifyIdleDevicesWithoutMessagesPushNotificationExperimentTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/experiment/NotifyIdleDevicesWithoutMessagesPushNotificationExperimentTest.java index 9b37bf154..9bb1a6531 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/experiment/NotifyIdleDevicesWithoutMessagesPushNotificationExperimentTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/experiment/NotifyIdleDevicesWithoutMessagesPushNotificationExperimentTest.java @@ -53,7 +53,7 @@ void isDeviceEligible(final Account account, final boolean mayHaveMessages, final boolean expectEligible) { - when(messagesManager.mayHaveMessages(account.getIdentifier(IdentityType.ACI), device)) + when(messagesManager.mayHavePersistedMessages(account.getIdentifier(IdentityType.ACI), device)) .thenReturn(CompletableFuture.completedFuture(mayHaveMessages)); when(idleDeviceNotificationScheduler.isIdle(device)).thenReturn(isDeviceIdle);