Skip to content

Commit

Permalink
Merge pull request #3 from datopian/fix/improve-recent-resources
Browse files Browse the repository at this point in the history
Efficiently get latest 5 resources for homepage
  • Loading branch information
anuveyatsu authored Nov 22, 2021
2 parents d897222 + bc92e1e commit f122396
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions ckanext/nhs/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,9 @@ def get_latest_datasets():
return datasets

def get_latest_resources():
context = {}
#number_of_active_resources = model.Resource.active().count()
#offset = 0 if (number_of_active_resources < 10) else (number_of_active_resources - 10)
data_dict = {
'query': 'name:',
}

resources = _get_action('resource_search', context, data_dict)['results']

from operator import itemgetter
resources_sorted = sorted(resources, key=itemgetter('last_modified','created'), reverse=True)

return resources_sorted[:5]
resources = model.Session.query(model.Resource).order_by(
model.Resource.last_modified.desc()).limit(5)
return resources

def get_cookie_control_config():

Expand Down

0 comments on commit f122396

Please sign in to comment.