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

2019-07-24 00:17发布

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

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?

1条回答
一夜七次
2楼-- · 2019-07-24 00:51

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.

查看更多
登录 后发表回答