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!的帖子發布和回復功能產生的內容都是自動分表存儲,但是要注意如果用了采集或其他插件發布帖子和回復請記得修改對應的程序。