本文介绍了存储徽章标准的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在考虑如何在新网站上实现类似于 SO 的徽章功能.存储徽章标准的最佳方式是什么?

I've been thinking about how to implement the badge feature similar to SO's on a new website. What is the best way to store criteria for badges?

两个想法:

  • 所有代码
  • '第二个系统' - 创建一个元架构来定义徽章及其标准.在数据库中存储一些信息并让代码查询它以找出徽章及其标准.

有更好的方法吗?

推荐答案

规则.

您在系统中创建事件,并在事件流处理器中使用规则.

You create events in the system, and use rules within an event stream processor.

具体来说,假设您有一个发表 10 个帖子"的徽章.您不会为每个帖子运行select count(*) from posts where user = :user".相反,您有一个简单的规则来监视每条帖子,并计算它们",将规则状态存储在用户配置文件中.

Specifically, say you have a badge "made 10 posts". You don't run "select count(*) from posts where user = :user" for every post. Rather, you have a simple rule that watches each post come by, and "count them", storing the rules state in the user profile.

这样发 10 个帖子"和发 1,000,000 个"帖子一样便宜.

That way "made 10 posts" is as cheap as "made 1,000,000" posts.

这也使系统更具可扩展性.

This also makes the system much more extensible.

这篇关于存储徽章标准的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 19:55