Cache Registrars in memory

This replaces the memcache caching, which we think is overall a bad idea.
We load all registrars at once instead of caching each as needed, so that
the loadAllCached() methods can be cached as well, and therefore will
always produce results consistent with loadByClientIdCached()'s view of the
registrar's values. All of our prod registrars together total 300k of data
right now, so this is hardly worth optimizing further, and in any case this
will likely reduce latency even further since most requests will be
served out of memory.

While I was in the Registrar file I standardized the error messages for incorrect
password and clientId length to be the same format, and cleaned up a few
random things I noticed in the code.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=156151828
This commit is contained in:
cgoldfeder 2017-05-16 00:42:49 -07:00 committed by Ben McIlwain
parent 9a48aae107
commit c9d7e75946
17 changed files with 149 additions and 179 deletions

View file

@ -115,7 +115,7 @@ public final class ConsoleUiAction implements Runnable {
.render());
return;
}
Registrar registrar = Registrar.loadByClientId(sessionUtils.getRegistrarClientId(req));
Registrar registrar = Registrar.loadByClientIdCached(sessionUtils.getRegistrarClientId(req));
data.put(
"xsrfToken",
xsrfTokenManager.generateToken(userService.getCurrentUser().getEmail()));

View file

@ -122,7 +122,9 @@ public class SessionUtils {
if (contact == null) {
return Optional.absent();
}
Optional<Registrar> result = Optional.fromNullable(ofy().load().key(contact.getParent()).now());
String registrarClientId = contact.getParent().getName();
Optional<Registrar> result =
Optional.fromNullable(Registrar.loadByClientIdCached(registrarClientId));
if (!result.isPresent()) {
logger.severefmt(
"A contact record exists for non-existent registrar: %s.", Key.create(contact));
@ -132,7 +134,7 @@ public class SessionUtils {
/** @see #hasAccessToRegistrar(Registrar, String) */
private static boolean hasAccessToRegistrar(String clientId, final String gaeUserId) {
Registrar registrar = Registrar.loadByClientId(clientId);
Registrar registrar = Registrar.loadByClientIdCached(clientId);
if (registrar == null) {
logger.warningfmt("Registrar '%s' disappeared from Datastore!", clientId);
return false;