Skip to content

Commit

Permalink
Fetch dataset only once during event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Zharktas committed Feb 5, 2024
1 parent 50892e0 commit ab9f05d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ckanext/matomo/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ def fetch(dryrun, since, until, dataset):
except Exception as e:
log.exception('Error updating resource statistics for {}: {}'.format(resource_id, e))

pkg = None
if dataset:
pkg = package_show({'ignore_auth': True}, {'id': dataset})

# Resource datastore search sql events (API events)
for date_str, date_statistics in datastore_search_sql_events.items():
date = datetime.datetime.strptime(date_str, DATE_FORMAT)
Expand All @@ -194,8 +198,7 @@ def fetch(dryrun, since, until, dataset):
resource_id = match[1]
try:
resource = resource_show({'ignore_auth': True}, {'id': resource_id})
if dataset:
pkg = package_show({'ignore_auth': True}, {'id': dataset})
if pkg:
if pkg.id != resource['package_id']:
continue
except toolkit.ObjectNotFound:
Expand Down

0 comments on commit ab9f05d

Please sign in to comment.