webkit-perf.appspot.com should accept test results without medians
[WebKit-https.git] / Websites / webkit-perf.appspot.com / runs_handler.py
index 8793c28ebebb4c76b1522c7f7877c9ee4f5f382e..c73ec42b35e6a4fa1ff556129c996128d71a65df 100644 (file)
@@ -28,6 +28,7 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 import webapp2
+from google.appengine.api import memcache
 
 import json
 from time import mktime
@@ -45,25 +46,33 @@ from models import modelFromNumericId
 
 class RunsHandler(webapp2.RequestHandler):
     def get(self):
+        self.response.headers['Content-Type'] = 'application/json; charset=utf-8'
+
         try:
-            testId = int(self.request.get('id', 0))
-            branchId = int(self.request.get('branchid', 0))
-            platformId = int(self.request.get('platformid', 0))
+            test_id = int(self.request.get('id', 0))
+            branch_id = int(self.request.get('branchid', 0))
+            platform_id = int(self.request.get('platformid', 0))
         except TypeError:
             # FIXME: Output an error here
-            testId = 0
-            branchId = 0
-            platformId = 0
+            test_id = 0
+            branch_id = 0
+            platform_id = 0
 
         # FIXME: Just fetch builds specified by "days"
         # days = self.request.get('days', 365)
 
+        cache_key = Test.cache_key(test_id, branch_id, platform_id)
+        cache = memcache.get(cache_key)
+        if cache:
+            self.response.out.write(cache)
+            return
+
         builds = Build.all()
-        builds.filter('branch =', modelFromNumericId(branchId, Branch))
-        builds.filter('platform =', modelFromNumericId(platformId, Platform))
+        builds.filter('branch =', modelFromNumericId(branch_id, Branch))
+        builds.filter('platform =', modelFromNumericId(platform_id, Platform))
 
-        test = modelFromNumericId(testId, Test)
-        testName = test.name if test else None
+        test = modelFromNumericId(test_id, Test)
+        test_name = test.name if test else None
         test_runs = []
         averages = {}
         values = []
@@ -71,7 +80,7 @@ class RunsHandler(webapp2.RequestHandler):
 
         for build in builds:
             results = TestResult.all()
-            results.filter('name =', testName)
+            results.filter('name =', test_name)
             results.filter('build =', build)
             for result in results:
                 builderId = build.builder.key().id()
@@ -84,11 +93,12 @@ class RunsHandler(webapp2.RequestHandler):
                 values.append(result.value)
                 timestamps.append(posixTimestamp)
 
-        self.response.headers['Content-Type'] = 'application/json; charset=utf-8';
-        self.response.out.write(json.dumps({
+        result = json.dumps({
             'test_runs': test_runs,
             'averages': averages,
             'min': min(values) if values else None,
             'max': max(values) if values else None,
             'date_range': [min(timestamps), max(timestamps)] if timestamps else None,
-            'stat': 'ok'}))
+            'stat': 'ok'})
+        self.response.out.write(result)
+        memcache.add(cache_key, result)