在PHP/MySQL中处理未读的帖子 [英] Handling unread posts in PHP / MySQL

查看:111
本文介绍了在PHP/MySQL中处理未读的帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于个人项目,我需要使用PHP和MySQL建立一个论坛.对我来说,不可能使用已经构建的论坛包(例如phpBB).

For a personal project, I need to build a forum using PHP and MySQL. It is not possible for me to use an already-built forum package (such as phpBB).

我目前正在研究构建这样的应用程序所需的逻辑,但是这已经是漫长的一天,并且我正在努力为用户处理未读帖子.我所拥有的一种解决方案是拥有一个单独的表,该表实质上包含所有帖子ID和用户ID,以确定是否已读取它们:

I'm currently working through the logic needed to build such an application, but it's been a long day and I'm struggling with the concept of handling unread posts for users. One solution I had was to have a separate table which essentially holds all post IDs and user IDs, to determine if they've been read:

tbl_userReadPosts: user_id, post_id, read_timestamp

很显然,如果用户的ID出现在此表中,则表明他们已经阅读了该帖子.除非我们每天有成千上万的帖子(这在提议的系统中是不可能的)和成千上万的用户,否则这很好.该表将在几天甚至几天内变得巨大.

Obviously, if a user's ID appears in this table, we know they've read the post. This is great, except if we have thousdands of posts per day (which is more than possible in the system which is being proposed), and thousdands of users. This table would become huge within a matter of days, if not hours.

另一种选择是将用户的上一个活动作为时间戳进行跟踪,然后检索所有在其上一个活动被更新后发布的帖子.从理论上讲,这是可行的,但是,假设用户正在撰写一篇非常长的帖子,与此同时,几个成员还开始了新主题或在其他主题中回复了帖子.当用户提交他的新帖子时,他的上一个活动将被更新,因此与此同时不匹配.

Another option would be to track the user's last activity as a timestamp, and then retrieve all posts made after their last activity was updated. This works in theory, but let's say a user is writing an extremely long post, and in the meantime several members also start new threads or reply to posts in other threads. When the user submits his new post, his last activity would be updated, and thus not match those made in the meantime.

有人有经验吗?您是如何解决的?

Does anyone have experience with this, and how did you tackle it?

我已经检查了phpBB,看来系统为每个用户分配了一个自定义会话,并在此基础上工作,但是有关如何处理未读帖子的文档非常少.

I've checked in phpBB and it seems that the system assigns a custom session to each user, and works on that basis, but the documentation is pretty sparse as to how this deals with unread posts.

一如既往地感激收到的想法和意见.

Thoughts and opinions gratefully received, as always.

推荐答案

对不起,我很快回答了.您绝对不希望将已读取的信息存储在数据库中,因为已经推论出,该表将变得巨大.

Sorry for the quick answer but I only have a second. You definitely do not want to store the read information in the database, as you've already deduced, this table would become gigantic.

介于您已经建议的内容之间:存储用户的上一次活动,以及存储他们在cookie中看到的信息,以确定他们已经阅读了哪些线程/帖子.

Something in between what you've already suggested: Store the users last activity, and in conjunction with storing information of what they've seen in the cookie, to determine which threads/posts they've read already.

这会将存储卸载到客户端Cookie,这将大大提高效率.

This offloads the storage to the client side cookie, which is far more efficient.

这篇关于在PHP/MySQL中处理未读的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆