I used resource_show
in CKAN 2.7.3 API docs to get metadata from specific resources. In my tracking_summary
table, I have some resource which has tracking number larger than 0. However, when I use resource_show
with {'include_tracking': True}
, it shows both recent
and total
are 0.
My resource record in tracking_summary
table looks like:
url | running_total | recent_views
-----------------------------------------------------------------------------------------------------------------+---------------+--------------
/dataset/d5cd38f4-03df-450e-9eb8-4967bc9741da/resource/844625fb-80a9-445c-85e7-5be8f10ec57b/download/test.csv | 1 | 1
I verified that I have already ran the command of paster tracking update
and paster search-index rebuild
. I don't know what am I missing now.
I found out the cause. If we look at the the url
we stored in tracking_summary
table, it does not contain the http schema and domain: http://example.ckan.com
. However if we are querying a resource from resource
table, the url
will contain the full http url. Also, when you tried to call resource_show
API with {'include_tracking': True}
in your application, the get_for_resource(cls, url)
in Tracking
model will refer to the full url
instead of the partial one. So if we store the partial one, the get_for_resource
will fail at the line data = obj.filter_by(url=url).order_by(text('tracking_date desc')).first()
. Therefore, when we save resource url in tracking_summary
, we should store the full one such as: http://example.ckan.com/dataset/<package_id>/resource/<resource_id>/<file_name>
.