开发者

With Siena, what is the best way to know if an entity doesn't exist in GAE?

Actually:

return all().filter("name", name).count() == 0;

May be a b开发者_开发知识库etter way ?


Regarding performance I would go for something like:

return all().filter("name", name).get() == null;

I'm not sure about GAE but in SQL a limit 1 is several times faster than count, and obviously you don't need to know how many models have this value.


Your way is not bad as you filter on a field.

If you had known the key of the entity, you could have used:

return Model.getByKey(YourClass.class, id) == null

If you want to filter on a given field, you can also use the fetch keys only :

return all().filter("name", name).fetchKeys().size() == 0;

But I wonder which is the best in term of performance. It depends on performance of GAE datastore regarding "count" or "fetch keys only" operation.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜