From 77136219ab108adab9c0815164226253698009c5 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Tue, 31 Dec 2019 12:13:37 -0500 Subject: [PATCH] cache locale lookups --- .../java/bubble/service/cloud/GeoService.java | 16 +++++++++++----- utils/cobbzilla-wizard | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bubble-server/src/main/java/bubble/service/cloud/GeoService.java b/bubble-server/src/main/java/bubble/service/cloud/GeoService.java index d537bed4..b2332097 100644 --- a/bubble-server/src/main/java/bubble/service/cloud/GeoService.java +++ b/bubble-server/src/main/java/bubble/service/cloud/GeoService.java @@ -19,21 +19,23 @@ import bubble.model.cloud.NetLocation; import bubble.server.BubbleConfiguration; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.ArrayUtils; +import org.cobbzilla.util.collection.ExpirationMap; import org.cobbzilla.wizard.validation.SimpleViolationException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; import static bubble.model.cloud.RegionalServiceDriver.findClosestRegions; import static org.cobbzilla.util.collection.HasPriority.SORT_PRIORITY; -import static org.cobbzilla.util.daemon.ZillaRuntime.die; -import static org.cobbzilla.util.daemon.ZillaRuntime.empty; +import static org.cobbzilla.util.daemon.ZillaRuntime.*; import static org.cobbzilla.util.string.LocaleUtil.getDefaultLocales; -import static org.cobbzilla.wizard.resources.ResourceUtil.*; +import static org.cobbzilla.wizard.resources.ResourceUtil.invalidEx; +import static org.cobbzilla.wizard.resources.ResourceUtil.notFoundEx; @Service @Slf4j public class GeoService { @@ -203,9 +205,13 @@ public class GeoService { } } + private final Map firstLocaleCache = new ExpirationMap<>(); + public String getFirstLocale(Account account, String remoteHost, String langHeader) { - final List supportedLocales = getSupportedLocales(account, remoteHost, langHeader); - return empty(supportedLocales) ? null : supportedLocales.get(0); + return firstLocaleCache.computeIfAbsent(hashOf(account.getUuid(), remoteHost, langHeader), k -> { + final List supportedLocales = getSupportedLocales(account, remoteHost, langHeader); + return empty(supportedLocales) ? null : supportedLocales.get(0); + }); } public List getSupportedLocales(Account caller, String remoteHost, String langHeader) { diff --git a/utils/cobbzilla-wizard b/utils/cobbzilla-wizard index 275e0f3f..6c176203 160000 --- a/utils/cobbzilla-wizard +++ b/utils/cobbzilla-wizard @@ -1 +1 @@ -Subproject commit 275e0f3fdd4f10f5cdb04416c0d8cbb2092c065e +Subproject commit 6c17620340f77bb163e3a2089838d580181d9fbf