Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
833 views
in Technique[技术] by (71.8m points)

architecture - Best way to store Badge criteria?

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:

  • All code
  • 'Second system' - create a meta architecture for defining badges and their criteria. Store some info in the database and have code query it to figure out the badges and their criteria.

Are there better ways?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...