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; ...@@ -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.Email;
import com.google.appinventor.shared.rpc.project.GalleryApp; import com.google.appinventor.shared.rpc.project.GalleryApp;
import com.google.appinventor.shared.rpc.project.GalleryAppListResult; 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.GalleryComment;
import com.google.appinventor.shared.rpc.project.GalleryModerationAction; import com.google.appinventor.shared.rpc.project.GalleryModerationAction;
import com.google.appinventor.shared.rpc.project.GalleryReportListResult; import com.google.appinventor.shared.rpc.project.GalleryReportListResult;
...@@ -59,14 +58,18 @@ public class GalleryServiceImpl extends OdeRemoteServiceServlet implements Galle ...@@ -59,14 +58,18 @@ public class GalleryServiceImpl extends OdeRemoteServiceServlet implements Galle
GalleryStorageIoInstanceHolder.INSTANCE; GalleryStorageIoInstanceHolder.INSTANCE;
// fileExporter used to get the source code from project being published // fileExporter used to get the source code from project being published
private final FileExporter fileExporter = new FileExporterImpl(); private final FileExporter fileExporter = new FileExporterImpl();
private final GallerySettings settings;
@Override public GalleryServiceImpl() {
public GallerySettings loadGallerySettings() {
String bucket = Flag.createFlag("gallery.bucket", "").get(); String bucket = Flag.createFlag("gallery.bucket", "").get();
boolean galleryEnabled = Flag.createFlag("use.gallery",false).get(); boolean galleryEnabled = Flag.createFlag("use.gallery",false).get();
String envirnment = SystemProperty.environment.value().toString(); String envirnment = SystemProperty.environment.value().toString();
String adminEmail = Flag.createFlag("gallery.admin.email", "").get(); 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; return settings;
} }
......
...@@ -18,6 +18,7 @@ package com.google.appinventor.server.flags; ...@@ -18,6 +18,7 @@ package com.google.appinventor.server.flags;
public abstract class Flag<T> { public abstract class Flag<T> {
private final String name; private final String name;
private final T defaultValue; private final T defaultValue;
private T cachedValue = null;
protected Flag(String name, T defaultValue) { protected Flag(String name, T defaultValue) {
this.name = name; this.name = name;
...@@ -30,8 +31,11 @@ public abstract class Flag<T> { ...@@ -30,8 +31,11 @@ public abstract class Flag<T> {
* @return the current value of this flag. * @return the current value of this flag.
*/ */
public final T get() throws IllegalFlagValueException { public final T get() throws IllegalFlagValueException {
String value = System.getProperty(name); if (cachedValue == null) {
return (value == null) ? defaultValue : convert(value); String value = System.getProperty(name);
cachedValue = (value == null) ? defaultValue : convert(value);
}
return cachedValue;
} }
/** /**
...@@ -41,6 +45,7 @@ public abstract class Flag<T> { ...@@ -41,6 +45,7 @@ public abstract class Flag<T> {
*/ */
public final void setForTest(T value) { public final void setForTest(T value) {
System.setProperty(name, value.toString()); 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