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