1

我有一个大的(大约 20000 个)对象,我想根据 AlertSubscription 中包含的用户 ID 进行检索。在 GAE 上这需要 20 多秒,我想知道是否有可能更快?我已经使用标准查询在 5 秒内检索了 20000 个 AlertSubscriptions 对象,所以我认为 DeviceInfo 对象需要 20 多秒是很奇怪的。

我目前的逻辑如下:

  1. 获取警报订阅列表
  2. 获取与订阅相关的所有 DeviceInfo
  3. 为每个操作系统启动一项任务(Android、iOS、WP7/8)

因此,我需要一次性使用所有设备,因此使用光标不会有太大帮助。有没有办法为对象的 Key 添加索引以使其更快?我在 datastore-index.xml 文件中没有设置索引。

    List<com.googlecode.objectify.Key<DeviceInfo>> dKeys= new ArrayList<com.googlecode.objectify.Key<DeviceInfo>>(); 
    for (AlertSubscription s: filteredSubscriptions.values()) 
    {
        dKeys.add(new com.googlecode.objectify.Key<DeviceInfo>(DeviceInfo.class,s.user));

    }
    log.info("Getting keys " + filteredSubscriptions.size());
    Map<com.googlecode.objectify.Key<DeviceInfo>, DeviceInfo> fetched = ofy.get(dKeys);
    log.info("Got keys, looping now");
...
   @PersistenceCapable(identityType = IdentityType.APPLICATION)
   public class DeviceInfo {
      @PrimaryKey
      @Persistent
      @Indexed
      private Key key;
4

1 回答 1

0

这为我解决了它:

ObjectifyOpts opts = new ObjectifyOpts();
opts.setConsistency(Consistency.EVENTUAL);
Objectify ofy = ObjectifyService.begin(opts);

https://groups.google.com/forum/?fromgroups=#!topic/objectify-appengine/1dIi-JOK_k4

于 2013-03-07T20:12:46.427 回答