diff --git a/master/buildbot/data/buildsets.py b/master/buildbot/data/buildsets.py index 5270abbd5f9..b6b1ba78d86 100644 --- a/master/buildbot/data/buildsets.py +++ b/master/buildbot/data/buildsets.py @@ -94,8 +94,17 @@ class BuildsetsEndpoint(Db2DataMixin, base.Endpoint): def get(self, resultSpec, kwargs): complete = resultSpec.popBooleanFilter('complete') resultSpec.fieldMapping = self.fieldMapping - d = self.master.db.buildsets.getBuildsets( - complete=complete, resultSpec=resultSpec) + + branch = resultSpec.popStringFilter('branch') + if branch is not None: + count = None + if resultSpec.limit: + count = resultSpec.limit + d = self.master.db.buildsets.getRecentBuildsets(complete=complete, + branch=branch, count=count) + else: + d = self.master.db.buildsets.getBuildsets( + complete=complete, resultSpec=resultSpec) @d.addCallback def db2data(buildsets): diff --git a/master/buildbot/data/changes.py b/master/buildbot/data/changes.py index 27c4fe47b87..a5dc48108bd 100644 --- a/master/buildbot/data/changes.py +++ b/master/buildbot/data/changes.py @@ -42,6 +42,9 @@ def _fixChange(self, change, is_graphql): {'name': k, 'source': v[1], 'value': json.dumps(v[0])} for k, v in props.items() ] + change['builds'] = yield self.master.db.builds.getBuildsForChange( + change['changeid'] + ) else: sskey = ('sourcestamps', str(change['sourcestampid'])) change['sourcestamp'] = yield self.master.data.get(sskey) @@ -104,8 +107,14 @@ def get(self, resultSpec, kwargs): changes = [] else: if resultSpec is not None: - resultSpec.fieldMapping = self.fieldMapping - changes = yield self.master.db.changes.getChanges(resultSpec=resultSpec) + branch = resultSpec.popStringFilter('branch') + if branch is not None: + changes = yield self.master.db.changes.getChangesForBranch( + branch, resultSpec.order, resultSpec.limit + ) + else: + resultSpec.fieldMapping = self.fieldMapping + changes = yield self.master.db.changes.getChanges(resultSpec=resultSpec) results = [] for ch in changes: results.append((yield self._fixChange(ch, is_graphql='graphql' in kwargs))) diff --git a/master/buildbot/db/changes.py b/master/buildbot/db/changes.py index 6c3a7c6a227..9a8909bc6a3 100644 --- a/master/buildbot/db/changes.py +++ b/master/buildbot/db/changes.py @@ -250,6 +250,28 @@ def thd(conn): def _getDataFromRow(self, row): return row.changeid + @defer.inlineCallbacks + def getChangesForBranch(self, branch, order, count): + def thd(conn): + changes_tbl = self.db.model.changes + bsss_tbl = self.db.model.buildset_sourcestamps + + from_clause = changes_tbl.join(bsss_tbl, + changes_tbl.c.sourcestampid == bsss_tbl.c.sourcestampid) + if branch == 'all': + q = sa.select([changes_tbl.c.changeid.distinct()]).select_from( + from_clause) + else: + q = sa.select([changes_tbl.c.changeid.distinct()]).select_from( + from_clause).where(changes_tbl.c.branch == branch) + q = q.limit(count).order_by(changes_tbl.c.changeid.desc()) + rp = conn.execute(q) + changeids = [self._getDataFromRow(row) for row in rp] + rp.close() + return changeids + res = yield self.db.pool.do(thd) + return res + def getChanges(self, resultSpec=None): def thd(conn): # get the changeids from the 'changes' table