Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

speed up package_list action by only retrieving column we need (not whole package) from db #1042

Merged
merged 4 commits into from
Aug 1, 2013
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions ckan/logic/action/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is frowned upon in ckan

a) we avoid from ckan... import ... as it leads to circular imports of which we have too many but are slowly improving
b) imports should be in the head of the file (unless circular import hell prevents this)

additionally logic functions get model from the context
also package_revision_table should be in ckan.model which has crazy imports due to pylons

this sort of thing should work (model is already in the function on ln 70)

model = context['model']
package_revision_table  = model.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.
Expand Down