mirror of
https://github.com/google/nomulus.git
synced 2025-07-27 13:06:27 +02:00
Improve cache loading in Registries.java (#1558)
* Improve cache loading in Registries.java The loader for the TLD cache in Registries.java unnecessarily reads from another cache when running with SQL, potentially triggering additional database access. This code runs in the whois query path, and contributes to the high latency in sandbox.
This commit is contained in:
parent
767e3935af
commit
6dd6ebce75
1 changed files with 28 additions and 17 deletions
|
@ -24,6 +24,7 @@ import static com.google.common.collect.Maps.filterValues;
|
||||||
import static google.registry.model.CacheUtils.memoizeWithShortExpiration;
|
import static google.registry.model.CacheUtils.memoizeWithShortExpiration;
|
||||||
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
|
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
|
||||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||||
|
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||||
import static google.registry.util.CollectionUtils.entriesToImmutableMap;
|
import static google.registry.util.CollectionUtils.entriesToImmutableMap;
|
||||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||||
|
@ -38,6 +39,8 @@ import com.google.common.net.InternetDomainName;
|
||||||
import com.googlecode.objectify.Key;
|
import com.googlecode.objectify.Key;
|
||||||
import google.registry.model.tld.Registry.TldType;
|
import google.registry.model.tld.Registry.TldType;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
/** Utilities for finding and listing {@link Registry} entities. */
|
/** Utilities for finding and listing {@link Registry} entities. */
|
||||||
public final class Registries {
|
public final class Registries {
|
||||||
|
@ -58,9 +61,9 @@ public final class Registries {
|
||||||
() ->
|
() ->
|
||||||
tm().doTransactionless(
|
tm().doTransactionless(
|
||||||
() -> {
|
() -> {
|
||||||
|
if (tm().isOfy()) {
|
||||||
ImmutableSet<String> tlds =
|
ImmutableSet<String> tlds =
|
||||||
tm().isOfy()
|
auditedOfy()
|
||||||
? auditedOfy()
|
|
||||||
.load()
|
.load()
|
||||||
.type(Registry.class)
|
.type(Registry.class)
|
||||||
.ancestor(getCrossTldKey())
|
.ancestor(getCrossTldKey())
|
||||||
|
@ -68,13 +71,21 @@ public final class Registries {
|
||||||
.list()
|
.list()
|
||||||
.stream()
|
.stream()
|
||||||
.map(Key::getName)
|
.map(Key::getName)
|
||||||
.collect(toImmutableSet())
|
|
||||||
: tm().loadAllOf(Registry.class).stream()
|
|
||||||
.map(Registry::getTldStr)
|
|
||||||
.collect(toImmutableSet());
|
.collect(toImmutableSet());
|
||||||
return Registry.getAll(tlds).stream()
|
return Registry.getAll(tlds).stream()
|
||||||
.map(e -> Maps.immutableEntry(e.getTldStr(), e.getTldType()))
|
.map(e -> Maps.immutableEntry(e.getTldStr(), e.getTldType()))
|
||||||
.collect(entriesToImmutableMap());
|
.collect(entriesToImmutableMap());
|
||||||
|
} else {
|
||||||
|
EntityManager entityManager = jpaTm().getEntityManager();
|
||||||
|
Stream<?> resultStream =
|
||||||
|
entityManager
|
||||||
|
.createQuery("SELECT tldStrId, tldType FROM Tld")
|
||||||
|
.getResultStream();
|
||||||
|
return resultStream
|
||||||
|
.map(e -> ((Object[]) e))
|
||||||
|
.map(e -> Maps.immutableEntry((String) e[0], ((TldType) e[1])))
|
||||||
|
.collect(entriesToImmutableMap());
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue