是否有(廉价)方法来检查实体是否存在? [英] Is there a (cheap) way to check if a entity exists?
本文介绍了是否有(廉价)方法来检查实体是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些密钥,我唯一想知道的是数据存储中是否有匹配的实体。目前我在做:
I have some keys and the only thing I want to know is if there is a matching entity in datastore. currently I'm doing:
entities = db.get(keys)
for entity in entities:
if entity:
# some stuff
else:
# some other stuff
虽然这有效,但我只需要传递一个布尔值,而不是entier对象。有没有办法让这一点的代码更便宜?
While this works, I just need a boolean to be passed, not the entier object. Is there a way to make this bit of code a bit cheaper?
推荐答案
比较你现在正在做什么的速度使用按键查询一次一个地查询密钥。如果没有明确的赢家,则只需要按键查询,因为它的成本更低。
Compare the speed of what you're doing now against querying the keys one-at-a-time using a keys-only query. If there isn't a clear winner, take the keys-only query, since it costs less.
这篇关于是否有(廉价)方法来检查实体是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文