I need a help and suggestion. I’m a noob at query.
what my goals is I want to show the data that is returned not TRUE based on ElfStatisticJobBkp
. but I’m dealing with a big data where I can’t find the correct way to do the query.
the ElfStatisticJobBkp
table is a large data on the database and $thejobname which came from an API is also a large data. $thejobname can have like 3000 data and the table ElfStatisticJobBkp can have a data from 2 years ago.
Everytime I do the query operation down below it’s always get a request 504 Gateway Time-out The server didn’t respond in time.
I tried to reduce the limit of $thejobname data API from 3000 to 100 and it will do just fine but it won’t reach the goal to identify all jobs that is exist on the API.
if(isset($result->token)){
$ctm_token = $result->token;
$arr = array('Wait','Condition');
$testvar = implode("%20",$arr);
$getheld = 'false';
$getcycle = 'true';
$url = $endpoint.'/run/jobs/status?limit=3000&status='.$testvar.'&held='.$getheld.'&cyclic='.$getcycle.'';
$header2 = array();
$header2[] = 'Authorization: Bearer '.$ctm_token;
//GET JOB DATA
$curl_data = curl_init();
curl_setopt($curl_data, CURLOPT_URL, $url);
curl_setopt($curl_data, CURLOPT_HTTPHEADER, $header2);
curl_setopt($curl_data, CURLOPT_HTTPGET, true);
curl_setopt($curl_data, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_data, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl_data, CURLOPT_SSL_VERIFYHOST, FALSE);
$result2 = json_decode(curl_exec($curl_data));
}
$finalData = [];
if (!empty($result2) && $result2->returned > 0 && $result2->total > 0) {
foreach ($result2->statuses as $value){
if (isset($value->estimatedStartTime)){
foreach ($value->estimatedStartTime as $estimatedstart) {
//existing $thejobname, $orderdate_call, $getjobid and etc...
$currenttimetest = date('H:i:s', time());
$testing1 = date('H:i:s', strtotime($currenttimetest) - 60);
$testing2 = date('H:i:s', strtotime($currenttimetest) + 60);
$sql = new yiidbExpression('CAST(stat_job_start AS time)');
$statistic_job_within_range = false;
$statistic_job_within_range = ElfStatisticJobBkp::find()
->where(['stat_job_name'=>$thejobname, 'stat_job_group'=>$thesubapp])
->andWhere(['between', $sql, $testing1, $testing2])
->exists();
$statistic_job_anomaly = false;
$statistic_job_anomaly = ElfStatisticJobBkp::find()
->where(['stat_job_name'=>$thejobname, 'stat_job_group'=>$thesubapp])
->andWhere(['not like', 'stat_job_status', 'NOT OK'])
->exists();
if ($statistic_job_anomaly != false) {
if ($statistic_job_within_range != true && $is_acknowledged != true && $is_snoozed != true && $estimated_start_time->format('Y-m-d H:i:s') <= $current_of_time->format('Y-m-d H:i:s')) {
$rowData = array(
'orderdate' => $orderdate_call,
'jobid' => $getjobid,
'jobname' => $thejobname,
'subapp' => $thesubapp,
'status' => $thestatus,
'estimatestarttime' => $estimation_start_time_final,
'cycletype' => $desc_online_text2,
);
$finalData[] = $rowData;
}
}
break;
}
}
}
} else {
$result2 = Core::returnEmptyObject();
}
Is there a way to achieve this goal?