diff options
Diffstat (limited to 'utils/test/testapi/opnfv_testapi/resources')
-rw-r--r-- | utils/test/testapi/opnfv_testapi/resources/handlers.py | 35 | ||||
-rw-r--r-- | utils/test/testapi/opnfv_testapi/resources/result_handlers.py | 4 |
2 files changed, 27 insertions, 12 deletions
diff --git a/utils/test/testapi/opnfv_testapi/resources/handlers.py b/utils/test/testapi/opnfv_testapi/resources/handlers.py index 42372e837..0234c8a73 100644 --- a/utils/test/testapi/opnfv_testapi/resources/handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/handlers.py @@ -105,21 +105,36 @@ class GenericApiHandler(web.RequestHandler): query = {} data = [] sort = kwargs.get('sort') - page = kwargs.get('page') - last = kwargs.get('last') - per_page = kwargs.get('per_page') + page = kwargs.get('page', 0) + last = kwargs.get('last', 0) + per_page = kwargs.get('per_page', 0) cursor = self._eval_db(self.table, 'find', query) + records_count = yield cursor.count() + records_nr = records_count + if (records_count > last) and (last > 0): + records_nr = last + + pipelines = list() + if query: + pipelines.append({'$match': query}) if sort: - cursor = cursor.sort(sort) - if last and last != 0: - cursor = cursor.limit(last) - if page: - records_count = yield cursor.count() - total_pages, remainder = divmod(records_count, per_page) + pipelines.append({'$sort': sort}) + + if page > 0: + total_pages, remainder = divmod(records_nr, per_page) if remainder > 0: total_pages += 1 - cursor = cursor.skip((page - 1) * per_page).limit(per_page) + pipelines.append({'$skip': (page - 1) * per_page}) + pipelines.append({'$limit': per_page}) + else: + pipelines.append({'$limit': records_nr}) + + cursor = self._eval_db(self.table, + 'aggregate', + pipelines, + allowDiskUse=True) + while (yield cursor.fetch_next): data.append(self.format_data(cursor.next_object())) if res_op is None: diff --git a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py index 208af6da2..1773216c0 100644 --- a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py @@ -147,13 +147,13 @@ class ResultsCLHandler(GenericResultHandler): @in trust_indicator: query @required trust_indicator: False """ - limitations = {'sort': [('start_date', -1)]} + limitations = {'sort': {'start_date': -1}} last = self.get_query_argument('last', 0) if last is not None: last = self.get_int('last', last) limitations.update({'last': last}) - page = self.get_query_argument('page', 1) + page = self.get_query_argument('page', None) if page is not None: page = self.get_int('page', page) limitations.update({'page': page, |