From 5cc6143b295fc6dab5c66cc0b39eab572c93d92b Mon Sep 17 00:00:00 2001 From: kindly Date: Fri, 18 May 2012 01:54:00 +0100 Subject: [PATCH] [2403] home page speed improvments --- ckan/controllers/home.py | 5 ++++- ckan/logic/action/get.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ckan/controllers/home.py b/ckan/controllers/home.py index cfa139c9829..d1621d6fa0f 100644 --- a/ckan/controllers/home.py +++ b/ckan/controllers/home.py @@ -49,8 +49,11 @@ def index(self): c.package_count = query['count'] c.facets = query['facets'] - # group search data_dict = {'order_by': 'packages', 'all_fields': 1} + #only give the terms to group dictize that are returned in the facets + #as full results take a lot longer + if 'groups' in c.facets: + data_dict['groups'] = c.facets['groups'].keys() c.groups = ckan.logic.get_action('group_list')(context, data_dict) except SearchError, se: c.package_count = 0 diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py index aa5bfa98fa7..03a164f070b 100644 --- a/ckan/logic/action/get.py +++ b/ckan/logic/action/get.py @@ -221,6 +221,7 @@ def group_list(context, data_dict): model = context['model'] user = context['user'] api = context.get('api_version') + groups = data_dict.get('groups') ref_group_by = 'id' if api == 2 else 'name'; order_by = data_dict.get('order_by', 'name') if order_by not in set(('name', 'packages')): @@ -232,6 +233,8 @@ def group_list(context, data_dict): query = model.Session.query(model.Group).join(model.GroupRevision) query = query.filter(model.GroupRevision.state=='active') query = query.filter(model.GroupRevision.current==True) + if groups: + query = query.filter(model.GroupRevision.name.in_(groups)) if order_by == 'name': sort_by, reverse = 'name', False