GAE/P:有效地迁移到 NDB

GAE/P: Migrating to NDB efficiently

我终于从 db 升级到 ndb(这比我预期的要麻烦得多...)。

我使用了很多 ReferenceProperty 并且我已经将它们转换为 KeyProperty。现在,我使用 ReferenceProperty 的每个地方都需要添加一个显式获取,因为它以前是自动为我完成的。

我的问题是我是否应该重构我的代码以使其更有效率。我有很多使用 KeyProperty 的方法,我需要做一个明确的 get()。我想知道我是否应该更改这些方法以便将实体传递给它们而不是使用 KeyPropertyget().

ndb 的自动内存缓存是否足够好,我不需要重组?还是我应该重组我的代码以避免重复获取同一实体?

我们没有看到这里的巨大低效率。但是对于单个 HTTP GET/POST 我可能会得到同一个实体 3-5 次。

在您的情况下,In-Context Cache 将接管并为您节省数据库调用:

The in-context cache is fast; this cache lives in memory. When an NDB function writes to the Datastore, it also writes to the in-context cache. When an NDB function reads an entity, it checks the in-context cache first. If the entity is found there, no Datastore interaction takes place.

每个请求都会得到一个新的上下文。