mirror of
https://github.com/google/nomulus.git
synced 2025-07-25 20:18:34 +02:00
Replace PubApi master calls with replica (#1742)
This commit is contained in:
parent
7aec579d96
commit
78249e1329
8 changed files with 39 additions and 26 deletions
|
@ -15,7 +15,7 @@
|
|||
package google.registry.rdap;
|
||||
|
||||
import static google.registry.flows.domain.DomainFlowUtils.validateDomainName;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKeyCached;
|
||||
import static google.registry.request.Action.Method.GET;
|
||||
import static google.registry.request.Action.Method.HEAD;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
|
@ -60,7 +60,7 @@ public class RdapDomainAction extends RdapActionBase {
|
|||
}
|
||||
// The query string is not used; the RDAP syntax is /rdap/domain/mydomain.com.
|
||||
Optional<Domain> domain =
|
||||
loadByForeignKey(
|
||||
loadByForeignKeyCached(
|
||||
Domain.class,
|
||||
pathSearchString,
|
||||
shouldIncludeDeleted() ? START_OF_TIME : rdapJsonFormatter.getRequestTime());
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
package google.registry.rdap;
|
||||
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKeyCached;
|
||||
import static google.registry.model.index.ForeignKeyIndex.loadAndGetKey;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.replicaJpaTm;
|
||||
|
@ -188,7 +188,8 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
|
|||
private DomainSearchResponse searchByDomainNameWithoutWildcard(
|
||||
final RdapSearchPattern partialStringQuery) {
|
||||
Optional<Domain> domain =
|
||||
loadByForeignKey(Domain.class, partialStringQuery.getInitialString(), getRequestTime());
|
||||
loadByForeignKeyCached(
|
||||
Domain.class, partialStringQuery.getInitialString(), getRequestTime());
|
||||
return makeSearchResults(
|
||||
shouldBeVisible(domain) ? ImmutableList.of(domain.get()) : ImmutableList.of());
|
||||
}
|
||||
|
@ -389,7 +390,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
|
|||
Optional<String> desiredRegistrar = getDesiredRegistrar();
|
||||
if (desiredRegistrar.isPresent()) {
|
||||
Optional<Host> host =
|
||||
loadByForeignKey(
|
||||
loadByForeignKeyCached(
|
||||
Host.class,
|
||||
partialStringQuery.getInitialString(),
|
||||
shouldIncludeDeleted() ? START_OF_TIME : getRequestTime());
|
||||
|
@ -414,7 +415,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
|
|||
// through the subordinate hosts. This is more efficient, and lets us permit wildcard searches
|
||||
// with no initial string.
|
||||
Domain domain =
|
||||
loadByForeignKey(
|
||||
loadByForeignKeyCached(
|
||||
Domain.class,
|
||||
partialStringQuery.getSuffix(),
|
||||
shouldIncludeDeleted() ? START_OF_TIME : getRequestTime())
|
||||
|
@ -431,7 +432,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
|
|||
if (partialStringQuery.matches(fqhn)) {
|
||||
if (desiredRegistrar.isPresent()) {
|
||||
Optional<Host> host =
|
||||
loadByForeignKey(
|
||||
loadByForeignKeyCached(
|
||||
Host.class, fqhn, shouldIncludeDeleted() ? START_OF_TIME : getRequestTime());
|
||||
if (host.isPresent()
|
||||
&& desiredRegistrar
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package google.registry.rdap;
|
||||
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.replicaJpaTm;
|
||||
import static google.registry.rdap.RdapUtils.getRegistrarByIanaIdentifier;
|
||||
import static google.registry.rdap.RdapUtils.getRegistrarByName;
|
||||
import static google.registry.request.Action.Method.GET;
|
||||
|
@ -71,7 +71,7 @@ public class RdapEntityAction extends RdapActionBase {
|
|||
if (ROID_PATTERN.matcher(pathSearchString).matches()) {
|
||||
VKey<ContactResource> contactVKey = VKey.create(ContactResource.class, pathSearchString);
|
||||
Optional<ContactResource> contactResource =
|
||||
tm().transact(() -> tm().loadByKeyIfPresent(contactVKey));
|
||||
replicaJpaTm().transact(() -> replicaJpaTm().loadByKeyIfPresent(contactVKey));
|
||||
// As per Andy Newton on the regext mailing list, contacts by themselves have no role, since
|
||||
// they are global, and might have different roles for different domains.
|
||||
if (contactResource.isPresent() && isAuthorized(contactResource.get())) {
|
||||
|
|
|
@ -324,9 +324,11 @@ public class RdapEntitySearchAction extends RdapSearchActionBase {
|
|||
contactResourceList = ImmutableList.of();
|
||||
} else {
|
||||
Optional<ContactResource> contactResource =
|
||||
tm().transact(
|
||||
replicaJpaTm()
|
||||
.transact(
|
||||
() ->
|
||||
tm().loadByKeyIfPresent(
|
||||
replicaJpaTm()
|
||||
.loadByKeyIfPresent(
|
||||
VKey.create(
|
||||
ContactResource.class, partialStringQuery.getInitialString())));
|
||||
contactResourceList =
|
||||
|
|
|
@ -20,7 +20,7 @@ import static com.google.common.collect.ImmutableList.toImmutableList;
|
|||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static com.google.common.collect.ImmutableSetMultimap.toImmutableSetMultimap;
|
||||
import static google.registry.model.EppResourceUtils.isLinked;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.replicaJpaTm;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.rdap.RdapIcannStandardInformation.CONTACT_REDACTED_VALUE;
|
||||
import static google.registry.util.CollectionUtils.union;
|
||||
|
@ -357,10 +357,15 @@ public class RdapJsonFormatter {
|
|||
// Kick off the database loads of the nameservers that we will need, so it can load
|
||||
// asynchronously while we load and process the contacts.
|
||||
ImmutableSet<Host> loadedHosts =
|
||||
tm().transact(() -> ImmutableSet.copyOf(tm().loadByKeys(domain.getNameservers()).values()));
|
||||
replicaJpaTm()
|
||||
.transact(
|
||||
() ->
|
||||
ImmutableSet.copyOf(
|
||||
replicaJpaTm().loadByKeys(domain.getNameservers()).values()));
|
||||
// Load the registrant and other contacts and add them to the data.
|
||||
ImmutableMap<VKey<? extends ContactResource>, ContactResource> loadedContacts =
|
||||
tm().transact(() -> tm().loadByKeysIfPresent(domain.getReferencedContacts()));
|
||||
replicaJpaTm()
|
||||
.transact(() -> replicaJpaTm().loadByKeysIfPresent(domain.getReferencedContacts()));
|
||||
// RDAP Response Profile 2.7.3, A domain MUST have the REGISTRANT, ADMIN, TECH roles and MAY
|
||||
// have others. We also add the BILLING.
|
||||
//
|
||||
|
@ -439,9 +444,11 @@ public class RdapJsonFormatter {
|
|||
statuses.add(StatusValue.LINKED);
|
||||
}
|
||||
if (host.isSubordinate()
|
||||
&& tm().transact(
|
||||
&& replicaJpaTm()
|
||||
.transact(
|
||||
() ->
|
||||
tm().loadByKey(host.getSuperordinateDomain())
|
||||
replicaJpaTm()
|
||||
.loadByKey(host.getSuperordinateDomain())
|
||||
.cloneProjectedAtTime(getRequestTime())
|
||||
.getStatusValues()
|
||||
.contains(StatusValue.PENDING_TRANSFER))) {
|
||||
|
@ -899,7 +906,8 @@ public class RdapJsonFormatter {
|
|||
.replace("%repoIdField%", repoIdFieldName)
|
||||
.replace("%repoIdValue%", resourceVkey.getSqlKey().toString());
|
||||
historyEntries =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().createQuery(jpql).getResultList());
|
||||
replicaJpaTm()
|
||||
.transact(() -> replicaJpaTm().getEntityManager().createQuery(jpql).getResultList());
|
||||
}
|
||||
for (HistoryEntry historyEntry : historyEntries) {
|
||||
EventAction rdapEventAction =
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
package google.registry.rdap;
|
||||
|
||||
import static google.registry.flows.host.HostFlowUtils.validateHostName;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKeyCached;
|
||||
import static google.registry.request.Action.Method.GET;
|
||||
import static google.registry.request.Action.Method.HEAD;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
|
@ -62,7 +62,7 @@ public class RdapNameserverAction extends RdapActionBase {
|
|||
// If there are no undeleted nameservers with the given name, the foreign key should point to
|
||||
// the most recently deleted one.
|
||||
Optional<Host> host =
|
||||
loadByForeignKey(
|
||||
loadByForeignKeyCached(
|
||||
Host.class,
|
||||
pathSearchString,
|
||||
shouldIncludeDeleted() ? START_OF_TIME : getRequestTime());
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package google.registry.rdap;
|
||||
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKeyCached;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.replicaJpaTm;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.request.Action.Method.GET;
|
||||
|
@ -160,7 +160,7 @@ public class RdapNameserverSearchAction extends RdapSearchActionBase {
|
|||
.setIncompletenessWarningType(IncompletenessWarningType.COMPLETE);
|
||||
|
||||
Optional<Host> host =
|
||||
loadByForeignKey(Host.class, partialStringQuery.getInitialString(), getRequestTime());
|
||||
loadByForeignKeyCached(Host.class, partialStringQuery.getInitialString(), getRequestTime());
|
||||
|
||||
metricInformationBuilder.setNumHostsRetrieved(host.isPresent() ? 1 : 0);
|
||||
|
||||
|
@ -176,7 +176,7 @@ public class RdapNameserverSearchAction extends RdapSearchActionBase {
|
|||
private NameserverSearchResponse searchByNameUsingSuperordinateDomain(
|
||||
RdapSearchPattern partialStringQuery) {
|
||||
Optional<Domain> domain =
|
||||
loadByForeignKey(Domain.class, partialStringQuery.getSuffix(), getRequestTime());
|
||||
loadByForeignKeyCached(Domain.class, partialStringQuery.getSuffix(), getRequestTime());
|
||||
if (!domain.isPresent()) {
|
||||
// Don't allow wildcards with suffixes which are not domains we manage. That would risk a
|
||||
// table scan in many easily foreseeable cases. The user might ask for ns*.zombo.com,
|
||||
|
@ -194,7 +194,7 @@ public class RdapNameserverSearchAction extends RdapSearchActionBase {
|
|||
// We can't just check that the host name starts with the initial query string, because
|
||||
// then the query ns.exam*.example.com would match against nameserver ns.example.com.
|
||||
if (partialStringQuery.matches(fqhn)) {
|
||||
Optional<Host> host = loadByForeignKey(Host.class, fqhn, getRequestTime());
|
||||
Optional<Host> host = loadByForeignKeyCached(Host.class, fqhn, getRequestTime());
|
||||
if (shouldBeVisible(host)) {
|
||||
hostList.add(host.get());
|
||||
if (hostList.size() > rdapResultSetMaxSize) {
|
||||
|
|
|
@ -17,7 +17,7 @@ package google.registry.whois;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.replicaJpaTm;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -53,12 +53,14 @@ final class NameserverWhoisResponse extends WhoisResponseImpl {
|
|||
ImmutableMap<Host, String> hostRegistrars =
|
||||
subordinateHosts.isEmpty()
|
||||
? ImmutableMap.of()
|
||||
: tm().transact(
|
||||
: replicaJpaTm()
|
||||
.transact(
|
||||
() ->
|
||||
Maps.toMap(
|
||||
subordinateHosts.iterator(),
|
||||
host ->
|
||||
tm().loadByKey(host.getSuperordinateDomain())
|
||||
replicaJpaTm()
|
||||
.loadByKey(host.getSuperordinateDomain())
|
||||
.cloneProjectedAtTime(getTimestamp())
|
||||
.getCurrentSponsorRegistrarId()));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue