Best way to store Badge criteria?

后端 未结 2 523
不知归路
不知归路 2020-11-29 16:54

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?

Two ideas:

2条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 17:32

    Rules.

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

    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.

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

    This also makes the system much more extensible.

提交回复
热议问题