点击登录
  • 欢迎访问无限星辰技术博客,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏无限星辰吧
  • 无限星辰的淘宝店铺已经开张了哦,传送门:http://

discuz论坛的INNODB方案

Discuz!问题集 crx349 2047次浏览 0个评论 扫描二维码

DISCUZ!论坛的INNODB使用方案

代码修改
代码中主要是针对SELECT COUNT(*)全表搜索的时候的优化。所涉及的文件均在source/class/table文件夹内
首先需要在class/discuz/discus_database.php中增加一个count_all的方法,修改如下:
在339行插入如下代码:

 

public static function count_all($table) {
$linkId = 1;
if(!empty(self::$db->config[‘map’]) && !empty(self::$db->config[‘map’][$table])){
$linkId = self::$db->config[‘map’][$table];
}
$dbname = self::$db->config[$linkId][‘dbname’];
$table = self::$db->table_name($table);

self::$db->select_db(‘information_schema’);
$count = self::$db->result_first(“SELECT TABLE_ROWS FROM `TABLES` WHERE TABLE_SCHEMA = ‘$dbname’ AND TABLE_NAME = ‘$table'”);

X2.5文件修改列表
文件名
行数
主要修改
Common_block_permission
55
替换为:
return $where ? DB::result_first(‘SELECT  COUNT(*) FROM ‘.DB::table($this->_table).$where) :  DB::count_all($this->_table);
Common_block_style
34
替换为:
return $wheresql ?  DB::result_first(‘SELECT COUNT(*) FROM  ‘.DB::table($this->_table).$wheresql) : DB::count_all($this->_table);
Common_credit_log
120
替换为:
return $condition[0] ?  DB::result_first(‘SELECT COUNT(*) FROM %t ‘.$condition[0], $condition[1]) :  DB::count_all($this->_table);
Common_diy_data
51
替换为:
return $wheresql ?  DB::result_first(‘SELECT COUNT(*) FROM  ‘.DB::table($this->_table).$wheresql) : DB::count_all($this->_table);
Common_invite
63
替换为:
return $condition[0] ?  DB::result_first(‘SELECT COUNT(*) FROM %t ‘.$condition[0], $condition[1]) :  DB::count_all($this->_table);
Common_member
170,174,350,354
分别替换为:
$count = DB::count_all($this->_table);
$count +=  intval(DB::count_all(‘common_connect_guest’));
if(!DB::fetch_first(‘SELECT * FROM  ‘.$temptablename.’ LIMIT 1′)) {
if(DB::fetch_first(‘SELECT * FROM  ‘.$temptablename.’ LIMIT 1′)) {
Common_member_archive
48
替换为:
return isset($this->membersplit) ?  DB::count_all($this->_table) : 0;
Common_member_verify_info
49
替换为:
return $condition[0] ?  DB::result_first(‘SELECT COUNT(*) FROM %t ‘.$condition[0], $condition[1]) :  DB::count_all($this->_table);
Forum_attachtype
51
替换为:
return $wheresql ?  DB::result_first(“SELECT COUNT(*) FROM %t $wheresql”, $parameter) :  DB::count_all($this->_table);
Forum_grouplevel
27
替换为:
return DB::count_all($this->_table);
Forum_medallog
81
替换为:
return $where ?  DB::result_first(“SELECT COUNT(*) FROM  “.DB::table(‘forum_medallog’).” $where”) :  DB::count_all($this->_table);
Forum_thread
982,1023,1028
分别替换为:
return $wheresql ?  DB::result_first(“SELECT COUNT(*) FROM %t $wheresql”, $parameter) :  DB::count_all($this->_table);
return DB::count_all($this->get_table_name($tableid));
return $condition[0] ?  DB::result_first(‘SELECT COUNT(*) FROM %t ‘.$condition[0], $condition[1]) :  DB::count_all($this->get_table_name());
Home_blacklist
37
替换为:
return $wheresql ?  DB::result_first(“SELECT COUNT(*) FROM %t $wheresql”, $parameter) :  DB::count_all($this->_table);
Home_favorite
56
替换为:
return $wheresql ?  DB::result_first(“SELECT COUNT(*) FROM %t $wheresql “, $parameter)  : DB::count_all($this->_table);
Home_follow
100,112
分别替换为:
$count = $wheresql ? DB::result_first(“SELECT  COUNT(*) FROM %t $wheresql”, $parameter) :  DB::count_all($this->_table);
$count = $wheresql ?  DB::result_first(“SELECT COUNT(*) FROM %t $wheresql”, $parameter) :  DB::count_all($this->_table);
Home_follow_feed
76
替换为:
$count = $wheresql ? DB::result_first(“SELECT  COUNT(*) FROM %t $wheresql”, $parameter) :  DB::count_all($this->_table);
Home_friend
104
替换为:
return $wheresql ?  DB::result_first(‘SELECT COUNT(*) FROM %t ‘.$wheresql, $parameter) :  DB::count_all($this->_table);
Home_share
137,158,195
分别替换为:
return $wheresql ?  DB::result_first(‘SELECT COUNT(*) FROM %t ‘.$wheresql, $parameter) :  DB::count_all($this->_table);
return $wheresql ?  DB::result_first(‘SELECT COUNT(*) FROM %t ‘.$wheresql, $parameter) :  DB::count_all($this->_table);
return $wheresql ?  DB::result_first(‘SELECT COUNT(*) FROM %t ‘.$wheresql, $parameter) :  DB::count_all($this->_table);
Portal_topic
25,26
替换为:
$wheresql = empty($wherearr) ? ” : ‘  WHERE ‘.implode(‘ AND ‘, $wherearr);
                   return  $wheresql ? DB::result_first(‘SELECT COUNT(*) FROM  ‘.DB::table($this->_table).$wheresql) : DB::count_all($this->_table);
Portal_category_permission
54
替换为:
return $where ? DB::result_first(‘SELECT  COUNT(*) FROM ‘.DB::table($this->_table).$where) :  DB::count_all($this->_table);
注:此表依据17173INNODB转换方案修改。table目录修改的文件列表如附件table

数据库修改:修改除post,session表之外的所有表引擎为INNODB。

感谢作者:Luca. 原帖地址:http://www.discuz.net/thread-3251930-1-1.html


无限星辰 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明discuz论坛的INNODB方案
喜欢 (0)
[]
分享 (0)

您必须 登录 才能发表评论!