【发布时间】:2019-10-07 04:44:03
【问题描述】:
我正在使用 Google App Engine、标准环境、NDB 数据存储区、Python 2.7。每个项目的索引限制为 200 个。
为了减少索引的数量,我打算这样做:
我在模型中有三个字段,report_type、current_center_urlsafe_key 和 timestamp_entered。我需要找到数据存储区中具有 current_center_urlsafe_key 和 report_type 特定值的所有条目。我需要根据 timestamp_entered(升序和降序)对这些值进行排序。
这会消耗一个单独的复合索引,我想避免它。为了实现这个查询,我计划通过组合所有三个值来为每次写入添加一个单独的实体,如下所示:
center_urlsafe_key_report_type_timestamp = report_type + "***" + current_center_urlsafe_key + str(current_timestamp_ms)
然后我打算做一个这样的查询:
current_timestamp_ms = int(round(time.time() * 1000))
current_date = date.today()
date_six_months_back = common_increment_dateobj_by_months(self,current_date, -6)
six_month_back_timestamp = (date_six_months_back - date(1970, 1, 1)).total_seconds() * 1000
center_urlsafe_key_report_type_timestamp = report_type_selected + "***" + current_center_urlsafe_key + str(six_month_back_timestamp)
download_reports_forward = download_report_request_model.query(ndb.GenericProperty('center_urlsafe_key_report_type_timestamp') >= center_urlsafe_key_report_type_timestamp).order(ndb.GenericProperty('center_urlsafe_key_report_type_timestamp'))
download_reports_backward = download_report_request_model.query(ndb.GenericProperty('center_urlsafe_key_report_type_timestamp') >= center_urlsafe_key_report_type_timestamp).order(ndb.GenericProperty('-center_urlsafe_key_report_type_timestamp'))
我的问题是,如果我将时间戳添加为字符串并添加前缀 report_type+"****"+current_center_urlsafe_key,NDB Datastore 不等式过滤器会提供所需的结果吗? p>
【问题讨论】:
标签: google-app-engine google-cloud-datastore