webkit-perf.appspot.com should accept test results without medians
[WebKit-https.git] / Websites / webkit-perf.appspot.com / manifest_handler.py
index 4d487dccd4844b0acae4b5f294b6f36e636fbbde..e9056ab47dd183c28cbd0d6551e51718458a0c3e 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
 
@@ -40,55 +41,53 @@ from models import Test
 class ManifestHandler(webapp2.RequestHandler):
     def get(self):
         self.response.headers['Content-Type'] = 'text/plain; charset=utf-8';
-        self.response.out.write('{"testMap":')
+        cache = memcache.get('manifest')
+        if cache:
+            self.response.out.write(cache)
+            return
 
-        testMap = {}
-        platformIdMap = {}
-        branchIdMap = {}
+        test_map = {}
+        platform_id_map = {}
+        branch_id_map = {}
         for test in Test.all():
-            branchIds = [Branch.get(branchKey).id for branchKey in test.branches]
-            platformIds = [Platform.get(platformKey).id for platformKey in test.platforms]
-            testMap[test.id] = {
+            branch_ids = [Branch.get(branch_key).id for branch_key in test.branches]
+            platform_ids = [Platform.get(platform_key).id for platform_key in test.platforms]
+            test_map[test.id] = {
                 'name': test.name,
-                'branchIds': branchIds,
-                'platformIds': platformIds,
+                'branchIds': branch_ids,
+                'platformIds': platform_ids,
             }
 
-            for platformId in platformIds:
-                platformIdMap.setdefault(platformId, {'tests': [], 'branches': []})
-                platformIdMap[platformId]['tests'].append(test.id)
-                platformIdMap[platformId]['branches'] += branchIds
+            for platform_id in platform_ids:
+                platform_id_map.setdefault(platform_id, {'tests': [], 'branches': []})
+                platform_id_map[platform_id]['tests'].append(test.id)
+                platform_id_map[platform_id]['branches'] += branch_ids
 
-            for branchId in branchIds:
-                branchIdMap.setdefault(branchId, {'tests': [], 'platforms': []})
-                branchIdMap[branchId]['tests'].append(test.id)
-                branchIdMap[branchId]['platforms'] += platformIds
+            for branch_id in branch_ids:
+                branch_id_map.setdefault(branch_id, {'tests': [], 'platforms': []})
+                branch_id_map[branch_id]['tests'].append(test.id)
+                branch_id_map[branch_id]['platforms'] += platform_ids
 
-        self.response.out.write(json.dumps(testMap))
-        self.response.out.write(',"platformMap":')
-
-        platformMap = {}
+        platform_map = {}
         for platform in Platform.all():
-            if platform.id not in platformIdMap:
+            if platform.id not in platform_id_map:
                 continue
-            platformMap[platform.id] = {
+            platform_map[platform.id] = {
                 'name': platform.name,
-                'testIds': list(set(platformIdMap[platform.id]['tests'])),
-                'branchIds': list(set(platformIdMap[platform.id]['branches'])),
+                'testIds': list(set(platform_id_map[platform.id]['tests'])),
+                'branchIds': list(set(platform_id_map[platform.id]['branches'])),
             }
 
-        self.response.out.write(json.dumps(platformMap))
-        self.response.out.write(',"branchMap":')
-
-        branchMap = {}
+        branch_map = {}
         for branch in Branch.all():
-            if branch.id not in branchIdMap:
+            if branch.id not in branch_id_map:
                 continue
-            branchMap[branch.id] = {
+            branch_map[branch.id] = {
                 'name': branch.name,
-                'testIds': list(set(branchIdMap[branch.id]['tests'])),
-                'platformIds': list(set(branchIdMap[branch.id]['platforms'])),
+                'testIds': list(set(branch_id_map[branch.id]['tests'])),
+                'platformIds': list(set(branch_id_map[branch.id]['platforms'])),
             }
 
-        self.response.out.write(json.dumps(branchMap))
-        self.response.out.write('}')
+        result = json.dumps({'testMap': test_map, 'platformMap': platform_map, 'branchMap': branch_map})
+        self.response.out.write(result)
+        memcache.add('manifest', result)