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

Use search to get datasets, as it is significantly faster #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions ckanext/datajson/build_datajsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ def apply_jsonld_metadata_mapping(data, newdict):

# skip fields with no mapping to RDF
if k not in jsonld_metadata_mapping: continue

# specially handle 'keyword' which in JSON is packed in a comma-separated field
if k == "keyword":
v = v.split(",")

# specially handle literal fields with datatypes
if k in jsonld_metadata_datatypes:
Expand Down
26 changes: 23 additions & 3 deletions ckanext/datajson/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,27 @@ def validator(self):

def make_json():
# Build the data.json file.
packages = p.toolkit.get_action("current_package_list_with_resources")(None, {})
return [make_datajson_entry(pkg) for pkg in packages if pkg["type"] == "dataset"]

return [make_datajson_entry(dataset) for dataset in _get_ckan_datasets()]

def _get_ckan_datasets():

n = 500
page = 1
datasets = []

while True:
search_data_dict = {
'q': '*:*',
'fq': 'dataset_type:dataset',
'sort': 'metadata_modified desc',
'rows': n,
'start': n * (page - 1),
}

query = p.toolkit.get_action('package_search')({}, search_data_dict)
if len(query['results']):
datasets.extend(query['results'])
page = page + 1
else:
break
return datasets