From a4f0cf611070629addd14f0b63526729f2dcd467 Mon Sep 17 00:00:00 2001 From: Ian Ward Date: Tue, 28 May 2013 10:34:23 -0400 Subject: [PATCH] package_list performance fix --- ckan/logic/action/get.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py index f43601082ec..db6ac852558 100644 --- a/ckan/logic/action/get.py +++ b/ckan/logic/action/get.py @@ -69,16 +69,16 @@ def package_list(context, data_dict): ''' model = context["model"] api = context.get("api_version", 1) - ref_package_by = 'id' if api == 2 else 'name' _check_access('package_list', context, data_dict) - query = model.Session.query(model.PackageRevision) - query = query.filter(model.PackageRevision.state=='active') - query = query.filter(model.PackageRevision.current==True) - - packages = query.all() - return [getattr(p, ref_package_by) for p in packages] + from ckan.model.package import package_revision_table + col = (package_revision_table.c.id + if api == 2 else package_revision_table.c.name) + query = _select([col]) + query = query.where(_and_(package_revision_table.c.state=='active', + package_revision_table.c.current==True)) + return zip(*query.execute()) def current_package_list_with_resources(context, data_dict): '''Return a list of the site's datasets (packages) and their resources.