请选择 进入手机版 | 继续访问电脑版

Discuz!大师网

搜索
查看: 5809|回复: 2

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

[复制链接]
发表于 2018-10-5 11:11:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

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

回复 马甲回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|网站地图|小黑屋|展会网|Discuz站长论坛 |天天打卡

GMT+8, 2024-4-19 09:05 , Processed in 0.023194 second(s), 7 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表