From 9f2f1d52e7ce0e3475e6e179cdcb0fef1abb92f1 Mon Sep 17 00:00:00 2001 From: Omar Shykhkerimov Date: Wed, 8 Jun 2016 19:06:01 +0300 Subject: [PATCH] Refactor to a single request for latest apps Latest apps section did a single request for each app in the list. This patch refactors it with only one request for user's applications using 'in' operator. Solves the TODO. Change-Id: I76d9f48de30c7ec0299aad12e402080ea713c0d5 Closes-bug: #1559066 Depends-On: Ibd93233392552699f9fc02e7f1d92542de2597f1 --- muranodashboard/catalog/views.py | 25 +++++-------------- ..._request_latest_apps-4f6add404ab07c15.yaml | 7 ++++++ 2 files changed, 13 insertions(+), 19 deletions(-) create mode 100644 releasenotes/notes/single_request_latest_apps-4f6add404ab07c15.yaml diff --git a/muranodashboard/catalog/views.py b/muranodashboard/catalog/views.py index eacbd3891..211111819 100644 --- a/muranodashboard/catalog/views.py +++ b/muranodashboard/catalog/views.py @@ -182,25 +182,12 @@ def cleaned_latest_apps(request): Verifies, that apps in the list are either public or belong to current project. """ - - cleaned_apps, cleaned_app_ids = [], [] - for app_id in request.session.get('latest_apps', []): - try: - # TODO(kzaitsev): we have to update this to 1 request per list of - # apps. Should be trivial and should remove the need to verify that - # apps are available. bug/1559066 - app = api.muranoclient(request).packages.get(app_id) - except exc.HTTPNotFound: - continue - else: - if app.type != 'Application': - continue - if (app.owner_id == request.session['token'].project['id'] or - app.is_public): - cleaned_apps.append(app) - cleaned_app_ids.append(app_id) - request.session['latest_apps'] = collections.deque(cleaned_app_ids) - return cleaned_apps + id_param = "in:" + ",".join(request.session.get('latest_apps', [])) + query_params = {'type': 'Application', 'catalog': True, 'id': id_param} + user_apps = list(api.muranoclient(request).packages.filter(**query_params)) + request.session['latest_apps'] = collections.deque([app.id + for app in user_apps]) + return user_apps def clear_forms_data(func): diff --git a/releasenotes/notes/single_request_latest_apps-4f6add404ab07c15.yaml b/releasenotes/notes/single_request_latest_apps-4f6add404ab07c15.yaml new file mode 100644 index 000000000..6650aee9c --- /dev/null +++ b/releasenotes/notes/single_request_latest_apps-4f6add404ab07c15.yaml @@ -0,0 +1,7 @@ +--- + +features: + - Improved the performance of 'Recent Activity' panel at the + 'Browse Catalog' page. + It was done with refactoring single request for every latest app + with single for all, using new API 'in' operator. \ No newline at end of file