1. 程式人生 > >Discuz!教程之大型Discuz!論壇站點帖子表forum_post分表方案優化

Discuz!教程之大型Discuz!論壇站點帖子表forum_post分表方案優化

forum_post表是儲存主題和回覆內容的表,是discuz系統中儲存內容最多的一個表。對於內容較多的大型站點來說,隨著這個表的逐漸增大,已經嚴重影響了站點的開啟速度。Discuz!系統本身已經有了帖子分表功能,但是每次都要手動操作分表,過一段時間之後主表(forum_post)變的很大。本文介紹一種通過簡單修改資料表和系統程式的方法實現發帖回帖自動分表儲存。 執行思路:將forum_post平均分成10份,分別為pre_forum_post_0/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_0/pre_forum_post_1/pre_forum_post_2/.../pre_forum_post_9; 3、分別執行如下sql語句 delete from pre_forum_post_0 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!的帖子釋出和回覆功能產生的內容都是自動分表儲存,但是要注意如果用了採集或其他外掛釋出帖子和回覆請記得修改對應的程式。