diff options
author | Serena Feng <feng.xiaowei@zte.com.cn> | 2017-08-18 01:00:25 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-08-18 01:00:25 +0000 |
commit | 8151d9aacd51a5e8b9d68845fca6b15448210937 (patch) | |
tree | df466f87d5899dc1ea2e8a078af7fb725e55a630 /utils/test/testapi | |
parent | b6d124999387d3a1b86ba046a89f6e96863a9b55 (diff) | |
parent | 02a7345647ee4628044c1a4acfa6f110ce34fbd5 (diff) |
Merge "bugfix: testapi is killed because of oom_kill"
Diffstat (limited to 'utils/test/testapi')
-rw-r--r-- | utils/test/testapi/opnfv_testapi/resources/handlers.py | 32 | ||||
-rw-r--r-- | utils/test/testapi/opnfv_testapi/resources/result_handlers.py | 4 |
2 files changed, 19 insertions, 17 deletions
diff --git a/utils/test/testapi/opnfv_testapi/resources/handlers.py b/utils/test/testapi/opnfv_testapi/resources/handlers.py index 8a3a2db38..474a2033b 100644 --- a/utils/test/testapi/opnfv_testapi/resources/handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/handlers.py @@ -106,16 +106,22 @@ class GenericApiHandler(web.RequestHandler): per_page = kwargs.get('per_page', 0) if query is None: query = {} + pipelines = list() + pipelines.append({'$match': query}) total_pages = 0 if page > 0: cursor = dbapi.db_list(self.table, query) records_count = yield cursor.count() - total_pages = self._calc_total_pages(records_count, - last, - page, - per_page) - pipelines = self._set_pipelines(query, sort, last, page, per_page) + total_pages, return_nr = self._calc_total_pages(records_count, + last, + page, + per_page) + pipelines = self._set_pipelines(pipelines, + sort, + return_nr, + page, + per_page) cursor = dbapi.db_aggregate(self.table, pipelines) data = list() while (yield cursor.fetch_next): @@ -145,21 +151,17 @@ class GenericApiHandler(web.RequestHandler): if page > 1 and page > total_pages: raises.BadRequest( 'Request page > total_pages [{}]'.format(total_pages)) - return total_pages + return total_pages, records_nr @staticmethod - def _set_pipelines(query, sort, last, page, per_page): - pipelines = list() - if query: - pipelines.append({'$match': query}) + def _set_pipelines(pipelines, sort, return_nr, page, per_page): if sort: pipelines.append({'$sort': sort}) - if page > 0: - pipelines.append({'$skip': (page - 1) * per_page}) - pipelines.append({'$limit': per_page}) - elif last > 0: - pipelines.append({'$limit': last}) + over = (page - 1) * per_page + left = return_nr - over + pipelines.append({'$skip': over}) + pipelines.append({'$limit': per_page if per_page < left else left}) return pipelines diff --git a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py index 2bf1792f2..9389d266d 100644 --- a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py @@ -155,7 +155,7 @@ class ResultsCLHandler(GenericResultHandler): @type last: L{string} @in last: query @required last: False - @param page: which page to list + @param page: which page to list, default to 1 @type page: L{int} @in page: query @required page: False @@ -180,7 +180,7 @@ class ResultsCLHandler(GenericResultHandler): return self.get_int('last', self.get_query_argument('last', 0)) def page_limit(): - return self.get_int('page', self.get_query_argument('page', 0)) + return self.get_int('page', self.get_query_argument('page', 1)) limitations = { 'sort': {'_id': descend_limit()}, |