Avoids redundant call saving 2.5 seconds

This commit is contained in:
Maxi Redigonda 2020-07-29 15:36:18 -03:00
parent c4a2c48eae
commit 384f7c93d7

View File

@ -126,17 +126,17 @@ class SearchController extends Controller {
'allowedDepartments' => $allowedDepartmentsId, 'allowedDepartments' => $allowedDepartmentsId,
'staffId' => Controller::getLoggedUser()->id 'staffId' => Controller::getLoggedUser()->id
]; ];
/// All code until this comment takes ~0.001 seconds
$query = $this->getSQLQuery($inputs); $query = $this->getSQLQuery($inputs); /// ~2.402 seconds
$queryWithOrder = $this->getSQLQueryWithOrder($inputs); $queryWithOrder = $this->getSQLQueryWithOrder($inputs, $query); /// ~3.103 seconds
$totalCount = RedBean::getAll("SELECT COUNT(*) FROM (SELECT COUNT(*) " . $query . " ) AS T2", [':query' => "%" . $inputs['query'] . "%", ':queryAtBeginning' => $inputs['query'] . "%" ])[0]['COUNT(*)']; $totalCount = RedBean::getAll("SELECT COUNT(*) FROM (SELECT COUNT(*) " . $query . " ) AS T2", [':query' => "%" . $inputs['query'] . "%", ':queryAtBeginning' => $inputs['query'] . "%" ])[0]['COUNT(*)']; /// ~0.001 seconds
$ticketIdList = RedBean::getAll($queryWithOrder, [':query' => "%" . $inputs['query'] . "%", ':queryAtBeginning' => $inputs['query'] . "%"]); $ticketIdList = RedBean::getAll($queryWithOrder, [':query' => "%" . $inputs['query'] . "%", ':queryAtBeginning' => $inputs['query'] . "%"]); /// ~0.000 seconds
$ticketList = []; $ticketList = [];
foreach ($ticketIdList as $item) { foreach ($ticketIdList as $item) {
$ticket = Ticket::getDataStore($item['id']); $ticket = Ticket::getDataStore($item['id']);
array_push($ticketList, $ticket->toArray()); array_push($ticketList, $ticket->toArray());
} } /// Until here ~0.015 seconds
$ticketTableExists = RedBean::exec("select table_name from information_schema.tables where table_name = 'ticket';"); $ticketTableExists = RedBean::exec("select table_name from information_schema.tables where table_name = 'ticket';"); /// ~0.602 seconds
if($ticketTableExists){ if($ticketTableExists){
Response::respondSuccess([ Response::respondSuccess([
'tickets' => $ticketList, 'tickets' => $ticketList,
@ -146,10 +146,10 @@ class SearchController extends Controller {
}else{ }else{
Response::respondSuccess([]); Response::respondSuccess([]);
} }
} /// The whole function ~5.793 seconds
}
public function getSQLQuery($inputs) { public function getSQLQuery($inputs) {
/// $sqlQueryTime = microtime(true);
$tagsTableExists = RedBean::exec("select table_name from information_schema.tables where table_name = 'tag_ticket';"); $tagsTableExists = RedBean::exec("select table_name from information_schema.tables where table_name = 'tag_ticket';");
$ticketEventTableExists = RedBean::exec("select table_name from information_schema.tables where table_name = 'ticketevent';"); $ticketEventTableExists = RedBean::exec("select table_name from information_schema.tables where table_name = 'ticketevent';");
@ -160,11 +160,11 @@ class SearchController extends Controller {
$filters = ""; $filters = "";
$this->setQueryFilters($inputs, $filters); $this->setQueryFilters($inputs, $filters);
$query .= $filters . " GROUP BY ticket.id"; $query .= $filters . " GROUP BY ticket.id";
/// echo "(getSQLQuery: " . (microtime(true) - $sqlQueryTime) . ")";
return $query; return $query;
} }
public function getSQLQueryWithOrder($inputs) { public function getSQLQueryWithOrder($inputs, $query) {
$query = $this->getSQLQuery($inputs);
$order = ""; $order = "";
$query = "SELECT" . " ticket.id " . $query; $query = "SELECT" . " ticket.id " . $query;