我使用 Codeigniter 创建了一个网站,我面临与速度相关的问题。
所有其他功能都要快得多,但我不知道为什么加载需要太多时间。
那么只有一个查询会执行该操作,但等待时间太长了。
此问题是在首次加载网站时发生的。
// 控制器
function hardwareFolder($uId){
$Folder = $this->System_model->get_folder_category_id($uId);
$menu = [
[
'id' => 'all',
'pId' => '1',
'name' => _('All'),
'icon' => base_url('images/directory_icon.gif'),
'isParent' => true,
'checked' => true,
'nocheck' => true,
'open' => true,
'dirlevel' => 'main',
'dirType' => 'all',
],
[
'id' => $Folder[0]['c_type_id'],
'pId' => $Folder[0]['c_type_pid'],
'name' => 'Unfiled',
'icon' => base_url('images/unfield.png'),
'isParent' => true,
'checked' => true,
'nocheck' => true,
'open' => true,
'dirlevel' => 'main',
'dirType' => 'unfiled',
],
[
'id' => $Folder[1]['c_type_id'],
'pId' => $Folder[1]['c_type_pid'],
'name' => _('Shared'),
'icon' => base_url('images/sharedir.png'),
'isParent' => true,
'checked' => true,
'nocheck' => true,
'open' => true,
'dirlevel' => 'main',
'dirType' => 'shared',
],
];
return $this->output
->set_content_type('application/json')
->set_output(json_encode($menu));
}
// 型号
function get_folder_category_id($uid){
$q_s_type = "SELECT c_type_id,c_type_pid,c_type_name " .
"FROM `codeigniter_system_category_type` " .
" WHERE `c_type_pid` = 0 " .
"AND `c_type_name` = 'Others' " .
"AND `c_module` = 'System' " .
"AND `c_created_userID` = ".$uid .
" UNION SELECT c_type_id,c_type_pid,c_type_name ".
" FROM `codeigniter_system_category_type` " .
"WHERE `c_type_pid` = 0 " .
"AND `c_type_name` = 'Shared' " .
"AND `c_module` = 'System' " .
"AND `c_created_userID` = ".$uid;
return $this->db->query($q_s_type)->result_array();
}
用Ajax调用脚本。
答案 0 :(得分:0)
除非我非常错,否则唯一能改变这两个SELECT
陈述的罪行就是检查c_type_name
如果是这样,您可以简化UNION
,并通过更改
SELECT
function get_folder_category_id($uid){
$q_s_type = "SELECT c_type_id,c_type_pid,c_type_name " .
"FROM `codeigniter_system_category_type` " .
" WHERE `c_type_pid` = 0 " .
"AND `c_type_name` = 'Others' " .
"AND `c_module` = 'System' " .
"AND `c_created_userID` = ".$uid .
" UNION SELECT c_type_id,c_type_pid,c_type_name ".
" FROM `codeigniter_system_category_type` " .
"WHERE `c_type_pid` = 0 " .
"AND `c_type_name` = 'Shared' " .
"AND `c_module` = 'System' " .
"AND `c_created_userID` = ".$uid;
return $this->db->query($q_s_type)->result_array();
}
function get_folder_category_id($uid){
$q_s_type = "SELECT c_type_id,c_type_pid,c_type_name " .
"FROM `codeigniter_system_category_type` " .
" WHERE `c_type_pid` = 0 " .
"AND `c_type_name` IN ('Others', 'Shared') " .
"AND `c_module` = 'System' " .
"AND `c_created_userID` = ".$uid;
return $this->db->query($q_s_type)->result_array();
}