下面你会找到一个名为getCalls
的CodeIgniter模型,我从控制器$manager, $level, $department, $id
在内部我执行以下操作:
$callInfo
我在数据库中通过所有已连接的列创建索引。
调用处理此模型的控制器时,我遇到速度问题。 Firebug告诉我加载页面大约需要30秒。
请注意,服务器性能和规格并不如您预期的那么好。这也是唯一的"复杂的屏幕"运行缓慢,我对下面的代码没有任何问题,只是一个速度问题。
请注意,我通过$ .ajax调用该页面,您可以找到以下功能...
请提出建议
function getCalls($manager, $level, $department, $id){
$callInfo = array();
$empMeta = array();
$MetaEmp = array();
$callMeta = array();
$MetaCall = array();
$TheCall = array();
if($manager == true && $level == '3'){
$query = $this->db->query("SELECT id_call, name_co, callStatus_call, dueDate_call, idemp_call FROM ecc_calls_call JOIN ecc_employees_emp ON idemp_call = id_emp JOIN ecc_company_co ON idco_call = id_co JOIN ecc_mempership_memper ON idemp_memper = idemp_call JOIN ecc_department_dep ON id_dep = iddep_memper WHERE status_call = 'active' && name_dep = {$department} ORDER BY id_call DESC");
if($query->num_rows() >= 1){
foreach($query->result() as $row){
//employee meta
$employee = $this->db->query("SELECT * FROM ecc_employee_empmeta WHERE idemp_empmeta = {$row->idemp_call}");
if($employee->num_rows() >= 1){
foreach($employee->result() as $rowEmp){
$empMeta[$rowEmp->metaKey_empmeta] = $rowEmp->metaValue_empmeta;
};
$MetaEmp = array(
'first_name' => $empMeta['first_name'],
'last_name' => $empMeta['last_name'],
'position' => $empMeta['position'],
'avatar' => $empMeta['avatar'],
'mobile' => $empMeta['mobile']
);
//return $MetaEmp;
}
//call meta
$call = $this->db->query("SELECT * FROM ecc_call_cmeta WHERE idcall_cmeta = {$row->id_call}");
if($call->num_rows() >= 1){
foreach($call->result() as $rowCall){
$callMeta[$rowCall->metaKey_cmeta] = $rowCall->metaValue_cmeta;
};
$MetaCall = array(
'inDate' => $callMeta['inDate'],
'feedback' => $callMeta['feedback'],
'reason' => $callMeta['reason']
);
}
$callInfo['id'] = $row->id_call;
$callInfo['name'] = $MetaEmp['first_name'] . " " . $MetaEmp['last_name'];
$callInfo['inDate'] = $MetaCall['inDate'];
$callInfo['feedback'] = $MetaCall['feedback'];
$callInfo['reason'] = $MetaCall['reason'];
$callInfo['company'] = $row->name_co;
$callInfo['dueDate_call'] = date('Y-m-d', strtotime($row->dueDate_call));
$callInfo['callStatus_call'] = $row->callStatus_call;
$TheCall[] = $callInfo;
}//foreach call
}//if
return $TheCall;
}elseif($level == 1){
$query = $this->db->query("SELECT id_call, name_co, callStatus_call, dueDate_call, idemp_call FROM ecc_calls_call JOIN ecc_employees_emp ON idemp_call = id_emp JOIN ecc_company_co ON idco_call = id_co WHERE status_call = 'active' ORDER BY id_call DESC");
if($query->num_rows() >= 1){
foreach($query->result() as $row){
//employee meta
$employee = $this->db->query("SELECT * FROM ecc_employee_empmeta WHERE idemp_empmeta = {$row->idemp_call}");
if($employee->num_rows() >= 1){
foreach($employee->result() as $rowEmp){
$empMeta[$rowEmp->metaKey_empmeta] = $rowEmp->metaValue_empmeta;
}
$MetaEmp = array(
'first_name' => $empMeta['first_name'],
'last_name' => $empMeta['last_name'],
'position' => $empMeta['position'],
'avatar' => $empMeta['avatar'],
'mobile' => $empMeta['mobile']
);
//return $MetaEmp;
}
//call meta
$call = $this->db->query("SELECT * FROM ecc_call_cmeta WHERE idcall_cmeta = {$row->id_call}");
if($call->num_rows() >= 1){
foreach($call->result() as $rowCall){
$callMeta[$rowCall->metaKey_cmeta] = $rowCall->metaValue_cmeta;
}
$MetaCall = array(
'inDate' => $callMeta['inDate'],
'feedback' => $callMeta['feedback'],
'reason' => $callMeta['reason']
);
}
$callInfo['id'] = $row->id_call;
$callInfo['name'] = $MetaEmp['first_name'] . " " . $MetaEmp['last_name'];
$callInfo['inDate'] = $MetaCall['inDate'];
$callInfo['feedback'] = $MetaCall['feedback'];
$callInfo['reason'] = $MetaCall['reason'];
$callInfo['company'] = $row->name_co;
$callInfo['dueDate_call'] = date('Y-m-d', strtotime($row->dueDate_call));
$callInfo['callStatus_call'] = $row->callStatus_call;
$TheCall[] = $callInfo;
}//foreach call
}//if
return $TheCall;
}elseif($level == 3){
$query = $this->db->query("SELECT id_call, name_co, callStatus_call, dueDate_call, idemp_call FROM ecc_calls_call JOIN ecc_employees_emp ON idemp_call = id_emp JOIN ecc_company_co ON idco_call = id_co WHERE status_call = 'active' && idemp_call = {$id} ORDER BY id_call DESC");
if($query->num_rows() >= 1){
foreach($query->result() as $row){
//employee meta
$employee = $this->db->query("SELECT * FROM ecc_employee_empmeta WHERE idemp_empmeta = {$row->idemp_call}");
if($employee->num_rows() >= 1){
foreach($employee->result() as $rowEmp){
$empMeta[$rowEmp->metaKey_empmeta] = $rowEmp->metaValue_empmeta;
}
$MetaEmp = array(
'first_name' => $empMeta['first_name'],
'last_name' => $empMeta['last_name'],
'position' => $empMeta['position'],
'avatar' => $empMeta['avatar'],
'mobile' => $empMeta['mobile']
);
//return $MetaEmp;
}
//call meta
$call = $this->db->query("SELECT * FROM ecc_call_cmeta WHERE idcall_cmeta = {$row->id_call}");
if($call->num_rows() >= 1){
foreach($call->result() as $rowCall){
$callMeta[$rowCall->metaKey_cmeta] = $rowCall->metaValue_cmeta;
}
$MetaCall = array(
'inDate' => $callMeta['inDate'],
'feedback' => $callMeta['feedback'],
'reason' => $callMeta['reason']
);
}
$callInfo['id'] = $row->id_call;
$callInfo['name'] = $MetaEmp['first_name'] . " " . $MetaEmp['last_name'];
$callInfo['inDate'] = $MetaCall['inDate'];
$callInfo['feedback'] = $MetaCall['feedback'];
$callInfo['reason'] = $MetaCall['reason'];
$callInfo['company'] = $row->name_co;
$callInfo['dueDate_call'] = date('Y-m-d', strtotime($row->dueDate_call));
$callInfo['callStatus_call'] = $row->callStatus_call;
$TheCall[] = $callInfo;
}//foreach call
}//if
return $TheCall;
}
}
这是ajax函数......
$.ajax({
type: 'GET',
url: "<?php echo base_url() . 'boffice/dataTable/'; ?>" + type + "/" + arg,
//data: {},//add variables
beforeSend:function(){
//this is were the loading image load
$('.PreviewHere').append('<div class="preloading"><img src="<?php echo base_url() . "assets/images/loading.gif"; ?>" alt="تحميل" /></div>').show();
},
success: function(data){
//successful request, do somthing with the data
$('.PreviewHere').html(data).show();
$(".preloading").remove();
},
error: function(){
//failed request
},
datatype: 'html'
})//ajax