Java App Engine - 排名计数器
我了解分片计数器,如下:http://code.google.com/appengine/ articles/sharding_counters.html 问题是简单的计数器在我的应用程序中不起作用。我按特定变量对实体进行排序,因此返回的不是计数,而是排名。我当前的方法是:
SELECT COUNT(this) FROM Entity.class WHERE value <= ?
结果+1是参数相对于持久实体对象中的值变量的排名。这样做的限制是返回的最高排名是 1001,因为 count() 最多可以给出 1000。 我无法在实体对象上存储排名的原因是排名经常更新,重新设置此排名变量的成本太高。
关于实现这一目标的最佳方法有什么想法吗?
I understand the sharded counter, here: http://code.google.com/appengine/articles/sharding_counters.html The problem is that a simple counter will not work in my application. I am sorting my entities by a particular variable so I am returned not so much a count, but more of a rank. My current method is:
SELECT COUNT(this) FROM Entity.class WHERE value <= ?
Result + 1 is then the rank of the parameter in relation to the value variable in the persistent Entity objects. The limitation of this is the highest rank being returned is 1001 because count() can give a maximum of 1000.
The reason I cannot store the rank on the Entity object is that the ranks are updated very often, and re-setting this rank variable would be much too costly.
Any ideas on the best way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能需要考虑调整 google-appengine-ranklist 项目到 Java。它构建了一个“ranker”节点树,这样可以在 O(log n) 时间内找到第 n 个排名项,并且更新同样为 O(log n)。
You might want to consider adapting something like the google-appengine-ranklist project to Java. It builds a tree of 'ranker' nodes, such that the nth ranked item can be found in O(log n) time, and updates are likewise O(log n).
我将创建一个带有静态变量的类来保存当前计数值。例如,您可以创建如下内容:
I would create a class with a static variable to hold the current count value. E.g., you could create something like the following: