xyz/forum.php,Discuz!教程之大型Discuz!论坛站点帖子表forum_post分表方案优化

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、修改系统文件source\class\model\model_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!的帖子发布和回复功能产生的内容都是自动分表存储,但是要注意如果用了采集或其他插件发布帖子和回复请记得修改对应的程序。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值