Best way to store Badge criteria?

喜夏-厌秋 提交于 2019-11-27 02:38:30

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.

I agree with Will on this one.

Create "events" over the pages so every time an event happens ie. a user deletes a post, it will query the event module with the event, lets say, EVENT_USER_DELETE_POST and then you can select that event and build a query based on it. You can then decide if a badge is awarded or not.

This will keep the two logics seperate and keep a modular design. It should be very easy to implement this way.

The only downside is that if the event was not "captured" then a user may well have earned a badge criteria but it has not yet been rewarded. However, this should never occur. The only situation I can think of is if the database is manipulated manually.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!