Discuz!教程之大型Discuz!论坛站点帖子表forum_post分表方案优化

admin 其他CMS教程 0

forum_post表是存储主题和回复内容的表,是discuz系统中存储内容最多的一个表。对于内容较多的大型站点来说,随着这个表的逐渐增大,已经严重影响了站点的打开速度。Discuz!系统本身已经有了帖子分表功能,但是每次都要手动操作分表,过一段时间之后主表(forum_post)变的很大。本文介绍一种通过简单修改数据表和系统程序的方法实现发帖回帖自动分表存储。

执行思路:将forum_post平均分成10份,分别为pre_forum_post/pre_forum_post_1/pre_forum_post_2/.../pre_forum_post_9,每次发帖回帖之后根据帖子tid按10取余数分别存在不同的表中。

具体执行步骤:

1、后台->全局,关闭网站。备份pre_forum_post表和pre_forum_thread表;

2、将数据库中的pre_forum_post连续复制10次,分别命名为pre_forum_post/pre_forum_post_1/pre_forum_post_2/.../pre_forum_post_9;

3、分别执行如下sql语句

delete from pre_forum_post where tid%10!=0;

delete from pre_forum_post_1 where tid%10!=1;

delete from pre_forum_post_2 where tid%10!=2;

delete from pre_forum_post_3 where tid%10!=3;

delete from pre_forum_post_4 where tid%10!=4;

delete from pre_forum_post_5 where tid%10!=5;

delete from pre_forum_post_6 where tid%10!=6;

delete from pre_forum_post_7 where tid%10!=7;

delete from pre_forum_post_8 where tid%10!=8;

delete from pre_forum_post_9 where tid%10!=9;

4、再执行如下sql语句

update pre_forum_thread set posttableid=tid%10;

5、修改系统文件sourceclassmodelmodel_forum_thread.php(修改前记得备份)

找到代码

$this->tid = C::t('forum_thread')->insert($newthread, true);

在这一行代码下方加入

$posttableid=($this->tid)%10;

if($posttableid){

C::t('forum_thread')->update($this->tid, array('posttableid' =>$posttableid));

}

5、后台,站长,帖子分表,点击更新备注信息。

6、后台,工具,更新缓存。

修改完成!

注意此方法修改后,所有通过discuz!的帖子发布和回复功能产生的内容都是自动分表存储,但是要注意如果用了采集或其他插件发布帖子和回复请记得修改对应的程序。

下载地址

免责声明

本站提供的一切软件、教程和内容信息仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑或手机中彻底删除上述内容。如果您喜欢该程序,请支持正版,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。敬请谅解!

您需要 登录账户 后才能发表评论

欢迎 你 发表评论: