您将在下面找到一个名为 CodeIgniter 的模型getCalls
,我从控制器向其传递以下值$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