更新实体的属性而不从NDB中检索实体 [英] updating an entity's property without retrieving the entity from the NDB

查看:129
本文介绍了更新实体的属性而不从NDB中检索实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新一个拥有很多属性的实体的属性。

I would like to update a property of an entity that has a lot of properties.

如果我正确地理解它,每当我从数据存储中检索实体时,

If I understand it correctly, whenever I retrieve the entity from the datastore by

entity = key_of_entity.get()

稍后更新它的属性

entity.some_property += 1
entity.put()

我需要阅读该实体的每个属性?由于这个实体具有不少属性,所以这样的阅读一遍又一遍可能是相当昂贵的。有没有办法更新一个实体的属性,而不必先读它?

I am charged for read of every property of that entity? Since this entity has quite a few properties, such reading over and over again can be quite expensive. Is there any way to update an entity's property without having to do a read on it first?

推荐答案

唯一的解决方案是将此实体分为两部分:很少更新并经常更新。你可以让它们完全独立(一个实体的ID作为另一个实体的属性),或者你可以让它们中的一个成为父母,另一个成为孩子。

The only solution is to split this entity into two parts: rarely updated and frequently updated. You can make them totally independent (with an id of one entity as a property in another entity), or you can make one of them a parent and the other one a child.

这篇关于更新实体的属性而不从NDB中检索实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆