我应该如何存储站点范围系统的用户级别?在DB?还是在飞?

时间:2021-01-31 07:10:32

I am in the process of building a user experience/level system on my site. The effect I am trying to achieve is similar to that of the popular game site, Kongregate, whereby when a user completes particular actions on the site they are awarded points. Once the points reach a certain amount the user will level up. This has the effect of giving the site a game like feel, while also grabbing the user's attention.

我正在我的网站上构建用户体验/级别系统。我试图实现的效果类似于流行的游戏网站Kongregate,当用户在网站上完成特定的操作时,他们会获得积分。一旦积分达到一定数量,用户将升级。这样可以为网站提供类似感觉的游戏,同时也能吸引用户的注意力。

The problem I'm having is figuring out if it's best to... 1. Store each level in a database table and then match the user up to that level via an ID? 2. OR store the user's experience for the actions completed and then summing that number up everytime I need to call on the level?

我遇到的问题是弄清楚是否最好...... 1.将每个级别存储在数据库表中,然后通过ID将用户匹配到该级别? 2.或者存储用户对完成的操作的体验,然后每次我需要在关卡上调用时将该数字相加?

It should also be noted that the level will be used to figure out other aspects of this system. i.e. A user at level 10 will gain additional schwag for their profile, added functionality on the site, etc... A LA Stack O.

还应该注意,该级别将用于计算该系统的其他方面。即10级用户将获得额外的schwag,他们的个人资料,网站上增加的功能等... A LA Stack O.

Any pointers on the proper direction to take?

有关正确方向的指示吗?

2 个解决方案

#1


3  

  • Store the levels and their associated "swag"/"privileges" in the database.
  • 将级别及其关联的“swag”/“特权”存储在数据库中。

  • Store the user's current level on their profile in the database.
  • 将用户的当前级别存储在数据库中的配置文件中。

  • Store the user's actions that result in points in the database
  • 存储导致数据库中的点的用户操作

When they add points from your site (by commenting, or playing a game or whatever), calculate it on the fly, but once it's definitely done adding up, store it in the database (in the actions table) and update their total points (in the user table or whatever) so it's available to other parts of the site.

当他们从你的网站添加点数(通过评论,或玩游戏或其他任何东西)时,可以动态计算,但一旦确定完成后,将其存储在数据库中(在动作表中)并更新其总点数(在用户表或其他任何内容)所以它可用于网站的其他部分。

This makes everything easier:

这使一切变得更容易:

  • when you want to see what privileges they have it's just a matter of comparing their total to the next lowest (or equal) "swag" level
  • 当你想看到他们拥有什么特权时,只需将他们的总数与下一个最低(或相等)的“赃物”水平进行比较

  • when you want to get their total it's a single call instead of a bunch of queries and math
  • 当你想得到他们的总数时,它只是一个电话而不是一堆查询和数学

  • when you want to show a list of what they've done you have it right in the database
  • 当你想要显示他们所做的事情的清单时,你就可以在数据库中找到它

  • You won't duplicate code by adding up their total on every different type of page that needs to show the total.
  • 您不会通过在需要显示总计的每个不同类型的页面上添加总计来重复代码。

  • ...probably tons of other reasons. data is in the name of the tool for a reason.
  • ...可能还有很多其他原因。出于某种原因,数据在工具的名称中。

#2


0  

I think it's best to determine the "level" everytime the user gets more points. So when he / she does something to get more points, do the calculation then and there. If the point warrants a level increase, then change the level_id within the user's profile. That way you minimize calculations on the server side.

我认为每次用户获得更多积分时最好确定“等级”。因此,当他/她做某事以获得更多积分时,然后进行计算。如果该点保证级别增加,则更改用户配置文件中的level_id。这样就可以最小化服务器端的计算。

#1


3  

  • Store the levels and their associated "swag"/"privileges" in the database.
  • 将级别及其关联的“swag”/“特权”存储在数据库中。

  • Store the user's current level on their profile in the database.
  • 将用户的当前级别存储在数据库中的配置文件中。

  • Store the user's actions that result in points in the database
  • 存储导致数据库中的点的用户操作

When they add points from your site (by commenting, or playing a game or whatever), calculate it on the fly, but once it's definitely done adding up, store it in the database (in the actions table) and update their total points (in the user table or whatever) so it's available to other parts of the site.

当他们从你的网站添加点数(通过评论,或玩游戏或其他任何东西)时,可以动态计算,但一旦确定完成后,将其存储在数据库中(在动作表中)并更新其总点数(在用户表或其他任何内容)所以它可用于网站的其他部分。

This makes everything easier:

这使一切变得更容易:

  • when you want to see what privileges they have it's just a matter of comparing their total to the next lowest (or equal) "swag" level
  • 当你想看到他们拥有什么特权时,只需将他们的总数与下一个最低(或相等)的“赃物”水平进行比较

  • when you want to get their total it's a single call instead of a bunch of queries and math
  • 当你想得到他们的总数时,它只是一个电话而不是一堆查询和数学

  • when you want to show a list of what they've done you have it right in the database
  • 当你想要显示他们所做的事情的清单时,你就可以在数据库中找到它

  • You won't duplicate code by adding up their total on every different type of page that needs to show the total.
  • 您不会通过在需要显示总计的每个不同类型的页面上添加总计来重复代码。

  • ...probably tons of other reasons. data is in the name of the tool for a reason.
  • ...可能还有很多其他原因。出于某种原因,数据在工具的名称中。

#2


0  

I think it's best to determine the "level" everytime the user gets more points. So when he / she does something to get more points, do the calculation then and there. If the point warrants a level increase, then change the level_id within the user's profile. That way you minimize calculations on the server side.

我认为每次用户获得更多积分时最好确定“等级”。因此,当他/她做某事以获得更多积分时,然后进行计算。如果该点保证级别增加,则更改用户配置文件中的level_id。这样就可以最小化服务器端的计算。