duanjiushu5063 2011-09-29 08:46
浏览 91
已采纳

我应该使用Global ID还是找到我的Notification系统的另一个解决方案?

So I have nearly finished my notification system, and just before I am about to implement reCAPTCHA, I test what happens if I spam the notifications.

To give you some background on my notification system. I determine the newest content, by its timestamp. I retrieve the rows from the database ORDER BY timestamp. The timestamp value is an integer formatted to Unix Time. When notifications are shown, they are hyperlinks, that follow this URL format -

http://test.com/article/id

Where id is the id for the table, each time a new article is submitted, the id increments. I noticed after spamming my notifications, that the URL's of the spammed notifications are in reverse order. After further investigation, I find that if I spam quick enough, the timestamp variable is not accurate enough, and records multiple submissions with the same timestamp.

Since my website is low traffic now, and there aren't many submissions, this is currently not an issue, but if, a very small chance, but if a piece of content is submitted at the same time as another, the notifications will rank when they were submitted wrongly, a small, but annoying bug.

So I'm wondering what I should do. Should I fix the issue, or is this an extremely minute chance of this happening. Due to the implementation of reCAPTCHA, spamming is not an issue, but there is still a chance this could happen by accident.

I have come up with 3 possible solutions. My question is which would be the most efficient

  1. Create a global id for all 4 types of content, which increments every time a comment, article or update is created.
  2. Use a more accurate PHP time function, such as microtime
  3. Add some sort of secondary ranking variable
  • 写回答

1条回答 默认 最新

  • dongpu3347 2011-09-29 09:49
    关注

    Given that there can be multiple threads and even multiple nodes in a cluster inserting data in different tables there is always a possibility that any clock based value you use will get duplicated in multiple, or even the same, table.

    So my first thought is to use a global id table. You could use a common content table with an auto-incrementing primary key that all other tables foreign key into and use that for ordering.

    On the other hand, by the same logic, how well can you ensure some fixed order between submissions? It is quite possible that two submissions will be committed to the database in the reverse order of receiving at the server. The only way to solve that problem I think is to a have a global gatekeeper that all requests have to pass through. If you are using such a gatekeeper, that is also the best place to assign the ordering value.

    All in all, I think you should not insist on complete ordering because it does not exist unless it is a highly ordering sensitive system such as Trading or Betting. Otherwise microsecond should be good enough, as long as the notification for a comment on a article does not come before the article itself.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀