简体   繁体   English

为什么从资源API获取的运单号与数据库中记录的运单号不同?

[英]Why tracking number get from resource API is different from the tracking number recorded in database?

I used resource_show inCKAN 2.7.3 API docs to get metadata from specific resources.我在CKAN 2.7.3 API 文档中使用了resource_show从特定资源中获取元数据。 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.在我的tracking_summary表中,我有一些资源的跟踪编号大于 0。但是,当我将resource_show{'include_tracking': True} ,它显示recenttotal都是 0。

My resource record in tracking_summary table looks like:我在tracking_summary表中的资源记录如下所示:

                                                       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 .我确认我已经运行了paster tracking updatepaster 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 .如果我们查看我们存储在tracking_summary表中的url ,它不包含 http 架构和域: http://example.ckan.com However if we are querying a resource from resource table, the url will contain the full http url.但是,如果我们从resource表中查询资源,则url将包含完整的 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.此外,当您尝试在应用程序中使用{'include_tracking': True}调用resource_show API 时, Tracking模型中的get_for_resource(cls, url)将引用完整url而不是部分url 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() .因此,如果我们存储部分的, get_for_resource将在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> .因此,当我们在tracking_summary保存资源 url 时,我们应该存储完整的,例如: http://example.ckan.com/dataset/<package_id>/resource/<resource_id>/<file_name>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM