MySQL 和按用户偏好安排的更新?

发布于 2024-12-10 11:43:30 字数 935 浏览 0 评论 0原文

我正在开发一个应用程序,它将

  • (用户的)电子邮件地址存储在表中。
  • 存储用户希望在表中停留的天数。
  • 当天数结束时,将用户从表中删除。

我真的不知道如何解决这个问题,所以这是我的问题:

  1. 每一秒,我是否让应用程序检查每个表条目中当前存储的时间,比如说,time_left柱子?
  2. 如果我预计有大量(10,000+)用户,那么 (1) 会不会效率低下?
  3. 如果不是(2),那么针对此类任务实现的最佳算法是什么?
  4. 我在这里尝试做的事情的名称是什么?我想在编写脚本之前和编写脚本时对其进行更多研究,因此我需要一个好的搜索查询来开始。

我计划用 Perl 编写这个脚本,尽管我愿意接受有关语言选择、​​框架等的建议......我实际上是 Web 开发的新手(后端和前端),所以如果您能给我准确的建议,我将不胜感激。

谢谢你!

*发帖后,Topener提出了一个有效的问题:

如果用户没有收到请求,为什么要存储用户?

假设用户只是坐在数据库中。

假设从用户添加到数据库后,我每 5 分钟使用一次用户的电子邮件地址(因此,如果用户的条目出生于 10 月 18 日下午 2:00,则该用户将在 2:05 被访问) 、2:10 等...)。

如果用户决定在 10 天内退出数据库,则意味着他们的条目正在正常访问(从 10 月 18 日下午 2:00 起每 5 分钟一次),直到 10 月 28 日下午 2:00 为止。

因此澄清一下,基于此情况:

系统必须不断将当前时间与用户的到期日期进行比较,不是吗?

I'm developing an application that

  • stores an e-mail address (to a user) in a table.
  • stores the number of days the user would like to stay in the table.
  • takes the user off the table when the number of days is up.

I don't really know how to approach this, so here are my questions:

  1. Each second, do I have the application check through every table entry for the time that's currently stored in, let's say, the time_left column?
  2. Wouldn't (1) be inefficient if I'm expecting a significant number (10,000+) users?
  3. If not (2), what's the best algorithm to implement for such a task?
  4. What's the name of what I'm trying to do here? I'd like to do some more research on it before and while I'm writing the script, so I need a good search query to start with.

I plan on writing this script in Perl, although I'm open to suggestions with regards to language choice, frameworks, etc... I'm actually new to web development (both on the back-end and front-end), so I'd appreciate it if you could advise me precisely.

Thank you!

*after posting, Topener asked a valid question:

Why would you store users if they won't get requested?

Assume the user is just sitting in the database.

Let's say I'm using the user's e-mail address every 5 minutes from the time the user was added to the database (so if the user's entry was born at 2:00PM-October 18, the user would be accessed at 2:05, 2:10, etc...).

If the user decides that they want out of the database in 10 days, that means their entry is being accessed normally (every 5 minutes from 2:00PM-October 18) until 2:00PM-October 28.

So to clarify, based on this situation:

The system would have to constantly compare the current time with the user's expiration date, wouldn't it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笨死的猪 2024-12-17 11:43:30

您不应该存储 time_left 变量,但您应该存储 vaildTo。这样,每当从数据库请求用户时,您都可以检查它是否有效。

如果没有,那就用它做任何你想做的事。

这种方法不会让你做任何 cronjobs,或者会花费你额外的负载。

you should not store the time_left variable, bt you should store vaildTo. This way, whenever the user is requested from the database, you can check if it is valid.

If not, then do whatever you want with it.

This approach wont let you make any cronjobs, or will cost you extramload.

冷情 2024-12-17 11:43:30

嘿 Mr_spock 我喜欢 Topener 的上述回答。存储用户希望被删除的日期,而不是存储用户希望有效的天数。

查询,

添加像 validToDate 这样的字段(它是 DATETIME 字段类型),您可以执行类似delete from tablename where validToDate <= NOW()

其中

  • 斜体 文本是SQL 查询
  • tablename 是相关表的名称
  • NOW() 是一个有效的 sql 函数,返回当前的 DATETIME
  • validToDate 是一个 DATETIME 类型的字段

这具有 SQL Server 承诺的效率,我认为它还算不错。

Hey Mr_spock I like the above answer from Topener. Instead of storing a number of days the user would like to be valid, store the day the user would like to be be removed.

Adding a field like validToDate, which would be a DATETIME field type, you can do a query like

delete from tablename where validToDate <= NOW()

where

  • the italicized text is a SQL query
  • tablename is the name of the table in question
  • NOW() is a valid sql function that returns the current DATETIME
  • validToDate is a field of type DATETIME

This has what ever efficiency SQL server promises, I think it is fairly good.

狠疯拽 2024-12-17 11:43:30

您可以编写一个单独的程序/脚本,以按设定的时间间隔进行删除查询。如果您使用的是 Linux 计算机,您可以创建一个 cron 作业来执行此操作。对于较慢的机器和较大的表来说,每秒执行一次可能会变得非常资源密集,但我不认为这会成为简单删除查询的问题。

You could write a separate program/script which makes the delete query on a set interval. If you are on a Linux machine you can create a cron job to do it. Doing it every second may become very resource intensive for slower machines and larger tables, but I don't believe that will become an issue for a simple delete query.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文