From e735aa6fb2287e2c974bbe6ebdb75b8bab63adc0 Mon Sep 17 00:00:00 2001 From: Miles Maddox Date: Thu, 17 Jan 2019 19:13:15 -0600 Subject: [PATCH] support for fetching all JQL results by way of pagination --- redash/query_runner/jql.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/redash/query_runner/jql.py b/redash/query_runner/jql.py index 2022f8f13a..de10508ad5 100644 --- a/redash/query_runner/jql.py +++ b/redash/query_runner/jql.py @@ -24,6 +24,8 @@ def add_column(self, column, column_type=TYPE_STRING): def to_json(self): return json_dumps({'rows': self.rows, 'columns': self.columns.values()}) + def merge(self, set): + self.rows = self.rows + set.rows def parse_issue(issue, field_mapping): result = OrderedDict() @@ -179,6 +181,19 @@ def run_query(self, query, user): results = parse_count(data) else: results = parse_issues(data, field_mapping) + index = data['startAt'] + data['maxResults'] + + while data['total'] > index: + query['startAt'] = index + response, error = self.get_response(jql_url, params=query) + if error is not None: + return None, error + + data = response.json() + index = data['startAt'] + data['maxResults'] + + addl_results = parse_issues(data, field_mapping) + results.merge(addl_results) return results.to_json(), None except KeyboardInterrupt: