【问题标题】:Is It Possible To Use A Cursor With Key-Only Queries?是否可以将光标与仅键查询一起使用?
【发布时间】:2015-11-07 10:48:45
【问题描述】:

我想知道是否可以在对数据存储的仅键查询上使用游标,经过数小时的查看并查看是否有解决方法,我什么也没得到。

我想这样做的原因是因为我想通过在内存缓存中缓存这些实体来节省数据存储读取。

我使用 Objectify 有以下查询:

Query<EventEntity> query = ofy().load().type(EventEntity.class).filter(combinedFilter).order("time").limit(50);

if(cursor != null){
    query = query.startAt(Cursor.fromWebSafeString(cursor));
}

QueryResultIterator<EventEntity> iterator = query.iterator();

【问题讨论】:

    标签: google-app-engine google-cloud-platform google-cloud-endpoints google-cloud-datastore objectify


    【解决方案1】:

    所以我“不聪明”,答案实际上很简单,只需在创建查询之后和迭代器之前调用 keys()

    Query<EventEntity> query = ofy().load().type(EventEntity.class).filter(combinedFilter).order("time").limit(50);
    
    if(cursor != null){
        query = query.startAt(Cursor.fromWebSafeString(cursor));
    }
    
    *QueryResultIterator<EventEntity> iterator = query.keys().iterator();*
    

    【讨论】:

      猜你喜欢
      • 2023-04-09
      • 2022-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-16
      • 1970-01-01
      相关资源
      最近更新 更多