瀏覽代碼

cache locale lookups

tags/v0.1.6
Jonathan Cobb 5 年之前
父節點
當前提交
77136219ab
共有 2 個檔案被更改,包括 12 行新增6 行删除
  1. +11
    -5
      bubble-server/src/main/java/bubble/service/cloud/GeoService.java
  2. +1
    -1
      utils/cobbzilla-wizard

+ 11
- 5
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<String, String> firstLocaleCache = new ExpirationMap<>();

public String getFirstLocale(Account account, String remoteHost, String langHeader) {
final List<String> supportedLocales = getSupportedLocales(account, remoteHost, langHeader);
return empty(supportedLocales) ? null : supportedLocales.get(0);
return firstLocaleCache.computeIfAbsent(hashOf(account.getUuid(), remoteHost, langHeader), k -> {
final List<String> supportedLocales = getSupportedLocales(account, remoteHost, langHeader);
return empty(supportedLocales) ? null : supportedLocales.get(0);
});
}

public List<String> getSupportedLocales(Account caller, String remoteHost, String langHeader) {


+ 1
- 1
utils/cobbzilla-wizard

@@ -1 +1 @@
Subproject commit 275e0f3fdd4f10f5cdb04416c0d8cbb2092c065e
Subproject commit 6c17620340f77bb163e3a2089838d580181d9fbf

Loading…
取消
儲存