像SO这样的徽章成就系统:正在使用的数据+标准(即时奖励和 cron 作业)
我一直在寻找 SO 的开源克隆,
http://github.com/cnprog/CNPROG
我不了解 Python/Django,但我仍然可以阅读正在发生的事情,
开发人员似乎只通过 cron 作业授予徽章, 奖项是通过方法颁发的,即标准的“规则”, 必须满足才能获得该奖项。
在这个文件中,这是Criteria ,
然而在best-way的答案中-to-store-badge-criteria 它说不运行类似的查询,
"select count(*) from posts where user = :user"// for every post.
这有点像 CNPROG 方法,而是改为
有一个简单的规则,用于监视每个帖子的出现,并“对它们进行计数”,将规则状态存储在用户个人资料中。
因此,“计算它们”一词是否意味着最好将所有内容记录在一个表中,例如,
class UserStats
int voteUpCount
int voteDownCount
int score
int commentCount
int viewCount
int offensiveFlagCount
int imageCount
int feedbackCount
int commentEditCount
int commentDeleteCount
int questionCount
int questionEditCount
int questionDeleteCount
然后使用这些数据使用简单的 if(commentCount > 10)...< /code> 根据用户发布的每条评论,然后执行 SQL 查询
Q 如果有人可以进一步解释问题的答案 best-way-to-store-badge-criteria,但给出一个包含“规则”、“标准”和数据库设计的示例
这些将与一些“每用户操作”和 cron 作业一起使用来提供徽章
I've been looking at an open source clone of SO,
http://github.com/cnprog/CNPROG
I don't know Python/Django but I can still read whats going on,
The developers, seem to only be awarding badges with cron jobs,
The awards are given out by the methods, being the "Rules" of the Criteria that
must be met to achieve the award.
in this file, which is the Criteria,
Yet In the answer to best-way-to-store-badge-criteria its saying not run a query like,
"select count(*) from posts where user = :user"// for every post.
Which is kind of like the CNPROG method, but to instead
have a simple rule that watches each post come by, and "count them", storing the rules state in the user profile.
So by the words "counting them", does that mean it would be better to record everything in one table like,
class UserStats
int voteUpCount
int voteDownCount
int score
int commentCount
int viewCount
int offensiveFlagCount
int imageCount
int feedbackCount
int commentEditCount
int commentDeleteCount
int questionCount
int questionEditCount
int questionDeleteCount
Then with this data make rules from it, with a simple if(commentCount > 10)...
upon every comment that the users posts, then preform the SQL query
Q If someone could further explain the answer from the question best-way-to-store-badge-criteria, But give an example with a "rule", "criteria" and database design
These would be used with some "per user action" and cron jobs to give badges
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的——你的直觉是正确的。这本质上就是数据库人员所说的物化视图。例如,给予帖子计数成就 > 30、做这样的事情:
当一个帖子插入到
posts
表中时,将1添加到users
表中的post_count
。如果 post_count > 30,设置has_thirty_posts = true。还有其他方法来存储架构。这只是一个粗略的简化,但它应该可以让您有所了解。这也称为反规范化(即存储冗余数据)。
Yes - your intuition is correct. This is essentially what the database people would call a materialized view. For example, to give an achievement for post count > 30, do something like this:
When a post is inserted into the
posts
table, add 1 topost_count
in theusers
table. Ifpost_count > 30
, sethas_thirty_posts = true
.There are other ways to store the schema. This is just a gross simplification, but it should give you the idea. This is also called Denormalization (i.e. storing redundant data).