google-app-engine - 不使用 Objectify 和 GAE 保存的对象

标签 google-app-engine loading objectify

我正在尝试保存一个对象并验证它是否在之后立即保存,但它似乎不起作用。

这是我的对象

import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;

@Entity
public class PlayerGroup {
    @Id public String n;//sharks
    public ArrayList<String> m;//members [39393,23932932,3223]

}

这是保存然后尝试立即加载的代码。

        playerGroup = new PlayerGroup();
        playerGroup.n = reqPlayerGroup.n;
        playerGroup.m = reqPlayerGroup.m;
        ofy().save().entity(playerGroup).now();
        response.i = playerGroup;
        PlayerGroup newOne = ofy().load().type(PlayerGroup.class).id(reqPlayerGroup.n).get();

但是“newOne”对象是空的。即使我刚刚完成保存。我做错了什么?

--更新-- 如果我稍后再试(比如几分钟后),有时我确实会看到该对象,但不是在保存后立即看到的。这与高复制存储有关吗?

最佳答案

前段时间有过同样的行为,并在 google groups - objectify 上问了一个问题

这里是我得到的答案:

You are seeing the eventual consistency of the High-Replication 
Datastore.  There has been a lot of discussion of this exact subject 
on the Objecify list in google groups , including several links to the 
Google documentation on the subject. 

Basically, any kind of query which does not include an ancestor() may 
return results from a stale view of the datastore. 

Jeff 

我也得到了另一个处理行为的好答案

For deletes, query for keys and then batch-get the entities. Make sure your gets are set to strong consistency (though I believe this is the default). The batch-get should return null for the deleted entities. When adding, it gets a little trickier. Index updates can take a few seconds. AFAIK, there are three ways out of this: 1; Use precomputed results (avoiding the query entirely). If your next view is the user's recently created entities, keep a list of those keys in the user entity, and update that list when a new entity is created. That list will always be fresh, no query required. Besides avoiding stale indexes, this also speeds up your app. The more you result sets you can reliably manage, the more queries you can avoid.

2; Hide the latency by "enhancing" the query results with the recently added entities. Depending on the rate at which you're adding entities, either inject only the most recent key, or combine this with the solution in 1.

3; Hide the latency by taking the user through some unaffected views before landing on your query-based view. This strategy definitely has a smell over it. You need to make sure those extra steps are relevant to the user, or you'll give a poor experience.

Butterflies, Joakim

您可以在这里阅读所有内容:

How come If I dont use async api after I'm deleting an object i still get it in a query that is being done right after the delete or not getting it right after I add one


类似问题的另一个好答案:Objectify doesn't store synchronously, even with now

关于google-app-engine - 不使用 Objectify 和 GAE 保存的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14651998/

相关文章:

python - 关于 appengine 索引的 3 个问题

javascript - 从 getElementById 加载图像时加载栏

java - 为什么 QueryResultIterator#getCursor() 在 GAE/J 中返回 null

java - 对象化仅键查询?

javascript - 如何通过 javascript 手动显示选项卡加载指示器?

java - 克服谷歌数据存储的 30 个子查询限制

java - AspectJ(注释)编译时与 Ant 和 NetBeans 编织

python - 谷歌应用引擎 webapp 中的 jinja2 autoescape 问题

python - 开发服务器 HTTP 错误 403 : Forbidden

c++ - 使用线程加载屏幕动画