Мои заявки занимают много времени, чтобы вернуть ответ.Что я могу сделать, чтобы сократить это время?
Я уже пробовал другую конфигурацию кэшей, но безуспешно.Я опубликую изображение моего таймера отладки для получения дополнительной информации.
Это мой контроллер:
private function returnData($childrens, $sucess, $result) {
$return = [
'success' => $sucess,
'data' => $result
];
if($childrens) {
$return = array_merge($return, ['childrens' => $childrens]);
}
$this->set($return);
$this->set('_serialize', true);
}
public function index()
{
$result = NULL;
$count = 0;
$status = false;
$childrens = false;
$message = NULL;
$method = 'index';
$this->request->allowMethod(['get']);
if ($this->request->is(['get'])) {
$params = $this->request->getQueryParams();
$response = $this->Functions->setParams($params);
$select = $response['select'];
$filter = $response['filter'];
$order = $response['order'];
$paginate = $response['paginate'];
$paginate = filter_var($paginate, FILTER_VALIDATE_BOOLEAN);
$autoFields = $response['autoFields'];
$autoFields = filter_var($autoFields, FILTER_VALIDATE_BOOLEAN);
$result = $this->MyModelName->find('search', ['search' => $filter])
->autoFields($autoFields)
->select($select)
->order($order);
if($paginate){
$result = $this->paginate($result);
}
$count = $result->count();
$this->setResponse($this->response->withStatus(200));
$message = $this->Functions->getStatusMessage(200, $method);
$status = true;
}
$result = $this->Functions->returnData($result, $message, $count, $select, $filter, $order, null);
$this->returnData($childrens, $status, $result);
}
Мой setParams:
public function setParams($params) {
$filter = [];
$order = [];
$select = [];
$table = [];
$controller = [];
$deptoId = [];
$autoFields = true;
$paginate = false;
$endpoint = null;
$userId = null;
if(isset($params)) {
if(isset($params['order'])) {
$param = $params['order'];
$arrs = explode(',', $param);
foreach($arrs as $arr) {
$arr1 = explode(':', $arr);
$arr2 = [$arr1[0] => $arr1[1]];
$order = array_merge($order, $arr2);
}
$order = str_replace(" ", "", $order);
}
if(isset($params['filter'])) {
$param = $params['filter'];
$arrs = explode(',', $param);
foreach($arrs as $arr) {
$arr1 = explode(':', $arr);
$arr2 = [$arr1[0] => $arr1[1]];
$filter = array_merge($filter, $arr2);
}
$filter = str_replace(" ", "", $filter);
}
if(isset($params['select'])) {
$param = $params['select'];
$select = explode(',', $param);
$select = str_replace(" ", "", $select);
}
if(isset($params['controller'])) {
$param = $params['controller'];
$controller = explode(',', $param);
$controller = str_replace(" ", "", $controller);
}
if(isset($params['tables'])) {
$param = $params['tables'];
$table = explode(',', $param);
$table = str_replace(" ", "", $table);
}
if(isset($params['autoFields'])) {
$param = $params['autoFields'];
$autoFields = $param;
$autoFields = str_replace(" ", "", $autoFields);
}
if(isset($params['paginate'])) {
$param = $params['paginate'];
$paginate = $param;
$paginate = str_replace(" ", "", $paginate);
}
if(isset($params['userId'])) {
$param = $params['userId'];
$userId = $param;
$userId = str_replace(" ", "", $userId);
}
if(isset($params['deptoId'])) {
$param = $params['deptoId'];
$deptoId = explode(',', $param);
$deptoId = str_replace(" ", "", $deptoId);
}
}
$ress = ['select' => $select,'filter' => $filter,'order' => $order,'table' => $table,'autoFields' => $autoFields,
'paginate' => $paginate, 'endpoint' => $endpoint, 'userId' => $userId, 'deptoId' => $deptoId, 'controller' => $controller];
return $ress;
}
Мой returnData:
public function returnData($result = null, $message = null, $count = null, $select = null, $filter = null, $order = null, $table = null) {
$result_res = [];
$message_res = [];
$count_res = [];
$status_res = [];
$filter_res = [];
$select_res = [];
$order_res = [];
$table_res = [];
if($filter && (is_null($count) || $count === 0)) {
$filter = implode("", $filter);
$message = is_null($message) ? 'Não foram encontrados registros com esse critério de filtro: ' . $filter : $message;
} else if(is_null($count) || $count === 0) {
$message = is_null($message) ? 'Não foram encontrados registros' : $message;
}
if($count) {
$count_res = ['count' => $count];
}
if($filter) {
$filter_res = ['filter' => $filter];
}
if($select) {
$select_res = ['select' => $select];
}
if($order) {
$order_res = ['order' => $order];
}
if($result) {
$result_res = ['data' => $result];
}
if($message) {
$message_res = ['message' => $message];
}
if($table) {
$table_res = ['table' => $table];
}
$result = array_merge($message_res, $count_res, $select_res, $order_res, $table_res, $result_res);
return $result;
My getStatusMessage:
public function getStatusMessage($code, $method)
{
switch (true) {
case $method == 'delete' && $code == 200:
$msg = 'SOME MSG.';
break;
case $method == 'delete' && $code == 400:
$msg = 'SOME MSG.';
break;
case $method == 'delete' && $code == 401:
$msg = 'SOME MSG.';
break;
case $method == 'delete' && $code == 404:
$msg = 'SOME MSG.';
break;
case $method == 'delete' && $code == 500:
$msg = 'SOME MSG.';
break;
case $method == 'delete':
$msg = 'SOME MSG.';
break;
case $method == 'add' && $code == 200:
$msg = 'SOME MSG.';
break;
case $method == 'add' && $code == 400:
$msg = 'SOME MSG.';
break;
case $method == 'add' && $code == 401:
$msg = 'SOME MSG.';
break;
case $method == 'add' && $code == 404:
$msg = 'SOME MSG.';
break;
case $method == 'add' && $code == 500:
$msg = 'SOME MSG.';
break;
case $method == 'add':
$msg = 'SOME MSG.';
break;
case $method == 'edit' && $code == 200:
$msg = 'SOME MSG.';
break;
case $method == 'edit' && $code == 400:
$msg = 'SOME MSG.';
break;
case $method == 'edit' && $code == 401:
$msg = 'SOME MSG.';
break;
case $method == 'edit' && $code == 404:
$msg = 'SOME MSG.';
break;
case $method =='edit' && $code == 500:
$msg = 'SOME MSG.';
break;
case $method =='edit':
$msg = 'SOME MSG.';
break;
case $method == 'index' && $code == 200:
$msg = 'SOME MSG.';
break;
case $method == 'index' && $code == 401:
$msg = 'SOME MSG.';
break;
case $method == 'index' && $code == 404:
$msg = 'SOME MSG.';
break;
case $method =='index':
$msg = 'SOME MSG.';
break;
case $method == 'list' && $code == 200:
$msg = 'SOME MSG.';
break;
case $method == 'list' && $code == 401:
$msg = 'SOME MSG.';
break;
case $method == 'list' && $code == 404:
$msg = 'SOME MSG.';
break;
case $method =='list':
$msg = 'SOME MSG.';
break;
case $method == 'view' && $code == 200:
$msg = 'SOME MSG.';
break;
case $method == 'view' && $code == 401:
$msg = 'SOME MSG.';
break;
case $method == 'view' && $code == 404:
$msg = 'SOME MSG.';
break;
case $method == 'view' && $code == 500:
$msg = 'SOME MSG.';
break;
case $method =='view':
$msg = 'SOME MSG.';
break;
case $method == 'multiples' && $code == 200:
$msg = 'SOME MSG.';
break;
case $method == 'multiples' && $code == 201:
$msg = 'SOME MSG.';
break;
case $method == 'multiples' && $code == 403:
$msg = 'SOME MSG.';
break;
case $method == 'multiples' && $code == 400:
$msg = 'SOME MSG.';
break;
case $method == 'multiples' && $code == 401:
$msg = 'SOME MSG.';
break;
case $method == 'multiples' && $code == 404:
$msg = 'SOME MSG.';
break;
case $method == 'multiples' && $code == 500:
$msg = 'SOME MSG.';
break;
case $method == 'multiples':
$msg = 'SOME MSG.';
break;
case $method == 'listuf' && $code == 200:
$msg = 'SOME MSG.';
break;
case $method == 'listuf' && $code == 401:
$msg = 'SOME MSG.';
break;
case $method == 'listuf' && $code == 404:
$msg = 'SOME MSG.';
break;
case $method == 'listuf' && $code == 500:
$msg = 'SOME MSG.';
break;
case $method =='listuf':
$msg = 'SOME MSG.';
break;
default:
$msg = 'Mensagem padrão.';
break;
}
return $msg;
}
Возможно ли быстрее вернуть этот ответ?