Commit b425deb7 authored by Evan W. Patton's avatar Evan W. Patton

Cache Flag and GallerySetting state

The loading of GallerySettings has a high latency in production. This
commit makes it so that the GallerySetting object is created only once
per GAE instance. It also updates the Flag class to cache the value on
first read since these flags are set in appengine-web.xml and are only
expected to change during deployment of a new version of App Inventor.

Change-Id: I7bb123697e821f2510807c5cbd5671bae71db307
parent 27f79871
......@@ -35,7 +35,6 @@ import com.google.appinventor.server.storage.GalleryStorageIoInstanceHolder;
import com.google.appinventor.shared.rpc.project.Email;
import com.google.appinventor.shared.rpc.project.GalleryApp;
import com.google.appinventor.shared.rpc.project.GalleryAppListResult;
import com.google.appinventor.shared.rpc.project.GalleryAppReport;
import com.google.appinventor.shared.rpc.project.GalleryComment;
import com.google.appinventor.shared.rpc.project.GalleryModerationAction;
import com.google.appinventor.shared.rpc.project.GalleryReportListResult;
......@@ -59,14 +58,18 @@ public class GalleryServiceImpl extends OdeRemoteServiceServlet implements Galle
GalleryStorageIoInstanceHolder.INSTANCE;
// fileExporter used to get the source code from project being published
private final FileExporter fileExporter = new FileExporterImpl();
private final GallerySettings settings;
@Override
public GallerySettings loadGallerySettings() {
public GalleryServiceImpl() {
String bucket = Flag.createFlag("gallery.bucket", "").get();
boolean galleryEnabled = Flag.createFlag("use.gallery",false).get();
String envirnment = SystemProperty.environment.value().toString();
String adminEmail = Flag.createFlag("gallery.admin.email", "").get();
GallerySettings settings = new GallerySettings(galleryEnabled, bucket, envirnment, adminEmail);
settings = new GallerySettings(galleryEnabled, bucket, envirnment, adminEmail);
}
@Override
public GallerySettings loadGallerySettings() {
return settings;
}
......
......@@ -18,6 +18,7 @@ package com.google.appinventor.server.flags;
public abstract class Flag<T> {
private final String name;
private final T defaultValue;
private T cachedValue = null;
protected Flag(String name, T defaultValue) {
this.name = name;
......@@ -30,8 +31,11 @@ public abstract class Flag<T> {
* @return the current value of this flag.
*/
public final T get() throws IllegalFlagValueException {
String value = System.getProperty(name);
return (value == null) ? defaultValue : convert(value);
if (cachedValue == null) {
String value = System.getProperty(name);
cachedValue = (value == null) ? defaultValue : convert(value);
}
return cachedValue;
}
/**
......@@ -41,6 +45,7 @@ public abstract class Flag<T> {
*/
public final void setForTest(T value) {
System.setProperty(name, value.toString());
cachedValue = null;
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment