Index: third_party/buildbot_8_4p1/buildbot/status/web/status_json.py |
diff --git a/third_party/buildbot_8_4p1/buildbot/status/web/status_json.py b/third_party/buildbot_8_4p1/buildbot/status/web/status_json.py |
index b656563257e3b0dbe89ca0e3fe26b330c1e7d99b..87a7f2da19fa470b1b7fd6ed605615b1b44ca78a 100644 |
--- a/third_party/buildbot_8_4p1/buildbot/status/web/status_json.py |
+++ b/third_party/buildbot_8_4p1/buildbot/status/web/status_json.py |
@@ -16,6 +16,7 @@ |
"""Simple JSON exporter.""" |
+import collections |
import datetime |
import os |
import re |
@@ -414,12 +415,14 @@ class BuilderSlavesJsonResources(JsonResource): |
pageTitle = 'BuilderSlaves' |
def __init__(self, status, builder_status): |
+ buildcache = collections.defaultdict(dict) |
M-A Ruel
2013/04/06 01:23:46
Why not create a single global instance? It'd be s
Mike Stip (use stip instead)
2013/04/06 01:30:28
Because this is per-request. It's only a cache whi
|
JsonResource.__init__(self, status) |
self.builder_status = builder_status |
for slave_name in self.builder_status.slavenames: |
self.putChild(slave_name, |
SlaveJsonResource(status, |
- self.status.getSlave(slave_name))) |
+ self.status.getSlave(slave_name), |
+ buildcache=buildcache)) |
class BuildJsonResource(JsonResource): |
@@ -620,12 +623,18 @@ class SlaveJsonResource(JsonResource): |
""" |
pageTitle = 'Slave' |
- def __init__(self, status, slave_status): |
+ def __init__(self, status, slave_status, buildcache=None): |
JsonResource.__init__(self, status) |
self.slave_status = slave_status |
self.name = self.slave_status.getName() |
self.builders = None |
+ # buildcache is used to cache build information across multiple |
+ # invocations of SlaveJsonResource. It should be set to an empty |
+ # collections.defaultdict(dict). Without it, each invocation will |
+ # do a full build scan. |
+ self.buildcache = buildcache or collections.defaultdict(dict) |
+ |
def getBuilders(self): |
if self.builders is None: |
# Figure out all the builders to which it's attached |
@@ -635,10 +644,7 @@ class SlaveJsonResource(JsonResource): |
self.builders.append(builderName) |
return self.builders |
- def asDict(self, request): |
- results = self.slave_status.asDict() |
- # Enhance it by adding more informations. |
- results['builders'] = {} |
+ def mapSlavesToBuilds(self): |
Isaac (away)
2013/04/05 23:45:01
delete this method and inline to line 662
Mike Stip (use stip instead)
2013/04/06 01:30:28
Done.
|
for builderName in self.getBuilders(): |
builds = [] |
builder_status = self.status.getBuilder(builderName) |
@@ -647,9 +653,19 @@ class SlaveJsonResource(JsonResource): |
if not build_status or not build_status.isFinished(): |
# If not finished, it will appear in runningBuilds. |
break |
- if build_status.getSlavename() == self.name: |
- builds.append(build_status.getNumber()) |
- results['builders'][builderName] = builds |
+ slave = self.buildcache[build_status.getSlavename()] |
+ slave.setdefault(builderName, []).append( |
M-A Ruel
2013/04/06 01:23:46
Note that it is effectively a memory leak, not a b
Mike Stip (use stip instead)
2013/04/06 01:30:28
buildcache gets thrown away after every request.
|
+ build_status.getNumber()) |
+ |
+ def getSlaveBuildMap(self): |
+ if not self.buildcache: |
+ self.mapSlavesToBuilds() |
+ return self.buildcache[self.name] |
+ |
+ def asDict(self, request): |
+ results = self.slave_status.asDict() |
+ # Enhance it by adding more informations. |
+ results['builders'] = self.getSlaveBuildMap() |
return results |
@@ -659,11 +675,13 @@ class SlavesJsonResource(JsonResource): |
pageTitle = 'Slaves' |
def __init__(self, status): |
+ buildcache = collections.defaultdict(dict) |
JsonResource.__init__(self, status) |
for slave_name in status.getSlaveNames(): |
self.putChild(slave_name, |
SlaveJsonResource(status, |
- status.getSlave(slave_name))) |
+ status.getSlave(slave_name), |
+ buildcache=buildcache)) |
class SourceStampJsonResource(JsonResource): |