开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜