mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-31 01:35:15 +02:00
Optimizes query to avoid information_schema (-2s)
This actually also corrects a bug (previous to this, the query would find any table with the correct name in any database).
This commit is contained in:
parent
2bf6b2c23f
commit
5b16393659
@ -107,11 +107,10 @@ class SearchController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function handler() {
|
public function handler() {
|
||||||
///$t1 = microtime(true);
|
|
||||||
$this->ignoreDeparmentFilter = (bool)Controller::request('supervisor');
|
$this->ignoreDeparmentFilter = (bool)Controller::request('supervisor');
|
||||||
$this->ticketTableExists = RedBean::exec("select table_name from information_schema.tables where table_name = 'ticket';"); /// ~0.602 seconds
|
$this->ticketTableExists = !empty(RedBean::getAll("SHOW TABLES LIKE 'ticket';"));
|
||||||
$this->tagsTableExists = RedBean::exec("select table_name from information_schema.tables where table_name = 'tag_ticket';");
|
$this->tagsTableExists = !empty(RedBean::getAll("SHOW TABLES LIKE 'tag_ticket';"));
|
||||||
$this->ticketEventTableExists = RedBean::exec("select table_name from information_schema.tables where table_name = 'ticketevent';");
|
$this->ticketEventTableExists = !empty(RedBean::getAll("SHOW TABLES LIKE 'ticketevent';"));
|
||||||
|
|
||||||
$allowedDepartmentsId = [];
|
$allowedDepartmentsId = [];
|
||||||
foreach (Controller::getLoggedUser()->sharedDepartmentList->toArray() as $department) {
|
foreach (Controller::getLoggedUser()->sharedDepartmentList->toArray() as $department) {
|
||||||
@ -143,7 +142,6 @@ class SearchController extends Controller {
|
|||||||
array_push($ticketList, $ticket->toArray());
|
array_push($ticketList, $ticket->toArray());
|
||||||
}
|
}
|
||||||
if($this->ticketTableExists){
|
if($this->ticketTableExists){
|
||||||
///echo '(handler: ' . (microtime(true) - $t1) . ")";
|
|
||||||
Response::respondSuccess([
|
Response::respondSuccess([
|
||||||
'tickets' => $ticketList,
|
'tickets' => $ticketList,
|
||||||
'pages' => ceil($totalCount / 10),
|
'pages' => ceil($totalCount / 10),
|
||||||
@ -152,10 +150,9 @@ class SearchController extends Controller {
|
|||||||
}else{
|
}else{
|
||||||
Response::respondSuccess([]);
|
Response::respondSuccess([]);
|
||||||
}
|
}
|
||||||
} /// The whole function ~1.93762321472166
|
}
|
||||||
|
|
||||||
public function getSQLQuery($inputs) {
|
public function getSQLQuery($inputs) {
|
||||||
///$sqlQueryTime = microtime(true);
|
|
||||||
$taglistQuery = ( $this->tagsTableExists ? " LEFT JOIN tag_ticket ON tag_ticket.ticket_id = ticket.id" : '');
|
$taglistQuery = ( $this->tagsTableExists ? " LEFT JOIN tag_ticket ON tag_ticket.ticket_id = ticket.id" : '');
|
||||||
$ticketeventlistQuery = ( $this->ticketEventTableExists ? " LEFT JOIN ticketevent ON ticketevent.ticket_id = ticket.id" : '');
|
$ticketeventlistQuery = ( $this->ticketEventTableExists ? " LEFT JOIN ticketevent ON ticketevent.ticket_id = ticket.id" : '');
|
||||||
|
|
||||||
@ -163,7 +160,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user