From 5150564fe28fcce77ea02dac86e5c920d79d706b Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Thu, 12 Oct 2023 09:59:43 -0300 Subject: [PATCH] Reduce donation configuration TTL to 1 hour. --- .../api/services/DonationsService.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libsignal-service/src/main/java/org/whispersystems/signalservice/api/services/DonationsService.java b/libsignal-service/src/main/java/org/whispersystems/signalservice/api/services/DonationsService.java index 5c1cc87808..220dd5e73d 100644 --- a/libsignal-service/src/main/java/org/whispersystems/signalservice/api/services/DonationsService.java +++ b/libsignal-service/src/main/java/org/whispersystems/signalservice/api/services/DonationsService.java @@ -35,6 +35,9 @@ import io.reactivex.rxjava3.annotations.NonNull; */ public class DonationsService { + private static final long DONATION_CONFIGURATION_TTL = TimeUnit.HOURS.toMillis(1); + private static final long SEPA_DEBIT_MANDATE_TTL = TimeUnit.DAYS.toMillis(1); + private static final String TAG = DonationsService.class.getSimpleName(); private final PushServiceSocket pushServiceSocket; @@ -112,7 +115,8 @@ public class DonationsService { return getCachedValue( locale, donationsConfigurationCache, - pushServiceSocket::getDonationsConfiguration + pushServiceSocket::getDonationsConfiguration, + DONATION_CONFIGURATION_TTL ); } @@ -120,13 +124,15 @@ public class DonationsService { return getCachedValue( locale, sepaBankMandateCache, - l -> pushServiceSocket.getBankMandate(l, "SEPA_DEBIT") + l -> pushServiceSocket.getBankMandate(l, "SEPA_DEBIT"), + SEPA_DEBIT_MANDATE_TTL ); } private ServiceResponse getCachedValue(Locale locale, AtomicReference> cachedValueReference, - CacheEntryValueProducer cacheEntryValueProducer + CacheEntryValueProducer cacheEntryValueProducer, + long cacheTTL ) { CacheEntry cacheEntryOutsideLock = cachedValueReference.get(); @@ -136,7 +142,7 @@ public class DonationsService { if (isNewCacheEntryRequired(cacheEntryInLock, locale)) { return wrapInServiceResponse(() -> { T value = cacheEntryValueProducer.produce(locale); - cachedValueReference.set(new CacheEntry<>(value, System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1), locale)); + cachedValueReference.set(new CacheEntry<>(value, System.currentTimeMillis() + cacheTTL, locale)); return new Pair<>(value, 200); }); } else {