开发者

Is there a (cheap) way to check if a entity exists?

开发者 https://www.devze.com 2023-04-12 09:26 出处:网络
I have some keys and th开发者_开发问答e only thing I want to know is if there is a matching entity in datastore. currently I\'m doing:

I have some keys and th开发者_开发问答e 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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号