dongpangbu4016 2010-09-29 15:29
浏览 75
已采纳

创建论坛灯泡(未读)系统的最有效方法是什么?

Alright, another interesting problem over at Route 50.

We wanted to implement a true forum lightbulb system where posts that are unread by a user (after the user's account is created) show as unread until that status is cleared or until the user reads them.

We figured the best and easiest way to do this would be to implement a table of unread messages.

The Columns are: user_id, board_id, thread_id, post_id, timestamp, and hidden

This is working very well and very quickly for seeing which boards/threads/posts are unread (and linking to them) per user, however it is INCREDIBLY slow for a user to post to the forum even though only a single SQL query is being run:

INSERT IGNORE INTO `forums_lightbulb` SELECT `id`,'x','x','x',UNIX_TIMESTAMP(),0 FROM `users`

I'm sure this is the result of having 3065 user accounts. How can I speed up this process? I'd prefer to keep the system as Real-Time as possible.

Important Note: Please limit your answers to a shared hosting environment with no additional budget. We are limited to PHP and MySQL 5.1.53-log

  • 写回答

4条回答 默认 最新

  • dongzen2675 2012-01-29 13:48
    关注

    What PHPBB does is a very quick way to do it. It keeps a table that marks for each thread and each forum when the last time was a user opened it. And uses that to determine if there are unread messages. It allows a Users*Topics + Users*Forums storage usage scheme while allowing a check with pretty simple and fast queries.

    You can see how it works from the database structure.

    # Table: 'phpbb_forums_track'
    CREATE TABLE phpbb_forums_track (
        user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
        forum_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
        mark_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
        PRIMARY KEY (user_id, forum_id)
    ) CHARACTER SET `utf8` COLLATE `utf8_bin`;
    
    # Table: 'phpbb_topics_track'
    CREATE TABLE phpbb_topics_track (
        user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
        topic_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
        forum_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
        mark_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
        PRIMARY KEY (user_id, topic_id),
        KEY topic_id (topic_id),
        KEY forum_id (forum_id)
    ) CHARACTER SET `utf8` COLLATE `utf8_bin`;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功