GAE的30个子查询限制的解决方法 [英] Workaround of GAE's 30 subqueries limitation

查看:98
本文介绍了GAE的30个子查询限制的解决方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在撰写新闻应用程序,并且希望让我的用户从包含数十(〜60)个来源(Guardian,Times,...)的列表中选择他们最喜欢的新闻来源。我有一个新闻实体,其中包含一个索引属性源,我正在寻找一种方法,可以让我绕过App Engine强加的30个子查询的限制,防止我使用IN和EQUALS过滤器获取所有新闻这是一个很大的来源列表。



是否有解决此限制的任何解决方法?



请记住,索引是昂贵的 - 它们占用大量空间并且增加写入成本。


$ b $ b

我会使用不同的设计。而不是60个子查询(以及如果源列表增长到500时会发生什么?)我会使源属性取消索引。然后,我会加载所有最新消息的列表并将其保存在Memcache中。如果你失去它,你可以随时重新加载它。您也可以根据消息的情况轻松地将更多项目添加到此列表中。您还可以根据时间将此列表分成块。



现在,当用户拨打电话时,您可以轻松过滤内存中的这个列表。根据您的使用量,这种设计可能会降低数十倍甚至数千倍,而且工作速度更快。最大的区别在于,不必一遍又一遍地读取每个用户请求的相同实体,只需读取一次并提供数千个请求,然后再次阅读。


I'm writing a news application and I want let my users choose their favourite news sources from a list that contains dozens (~60) of sources(Guardian,Times,...). I have a News entity that contains an indexed property "source" and I'm looking for an approach that will let me bypass the limitation of 30 subqueries imposed by App Engine that prevents me for using the IN and EQUALS filters to get all the news that belongs to a big list of sources.

is there any workaround for this limitation?

Thanks

解决方案

Remember that indexes are expensive - they take a lot of space and multiply the write costs.

I would use a different design. Instead of 60 subqueries (and what happens if your list of sources grows to 500?) I would make the source property unindexed. Then I would load a list of all the latest news and keep it in Memcache. If you lose it, you can always reload it. You can also easily add more items to this list as news come in. You can also split this list into chunks based on time.

Now as users make their calls, you can easily filter this list in memory. Depending on your usage volume, this design will be dozens - or thousands - of times cheaper and work much faster. The biggest difference is that instead of reading the same entities over and over for each user request, you will read them once and serve thousands of requests before you need to read them again.

这篇关于GAE的30个子查询限制的解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆