Skip to content

Commit

Permalink
Add a method to check for the presence of persisted messages, skippin…
Browse files Browse the repository at this point in the history
…g the cache
  • Loading branch information
jon-signal committed Jul 31, 2024
1 parent f1c153f commit 8220920
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public CompletableFuture<Boolean> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public void insert(UUID destinationUuid, byte destinationDevice, Envelope messag
}
}

public CompletableFuture<Boolean> mayHavePersistedMessages(final UUID destinationUuid, final Device destinationDevice) {
return messagesDynamoDb.mayHaveMessages(destinationUuid, destinationDevice);
}

public CompletableFuture<Boolean> mayHaveMessages(final UUID destinationUuid, final Device destinationDevice) {
return messagesCache.hasMessagesAsync(destinationUuid, destinationDevice.getId())
.thenCombine(messagesDynamoDb.mayHaveMessages(destinationUuid, destinationDevice),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8220920

Please sign in to comment.