Skip to content
Snippets Groups Projects
Commit 81b1e9d7 authored by Jared Hancock's avatar Jared Hancock Committed by Peter Rotich
Browse files

queue: Use nested criteria for the query

This changes the organization of the ticket queue query. It places the criteria of
the queue and the access criteria based on the staff in a query by itself. Then it
joins to that query and selects the columns and annotations in the outer query.

This seems to help MySQL focus on the query in two stages. The first is to find the
one page of results to be shown on the page, and the second is to find all the
information to be shown for each ticket.
parent f602cba3
Branches
Tags
No related merge requests found
......@@ -1491,6 +1491,10 @@ class QuerySet implements IteratorAggregate, ArrayAccess, Serializable, Countabl
$this->options[$option] = $value;
}
function clearOption($option) {
unset($this->options[$option]);
}
function countSelectFields() {
$count = count($this->values) + count($this->annotations);
if (isset($this->extra['select']))
......
......@@ -76,6 +76,18 @@ if (!$sorted && isset($sort['queuesort'])) {
$page = ($_GET['p'] && is_numeric($_GET['p']))?$_GET['p']:1;
$pageNav = new Pagenate(PHP_INT_MAX, $page, PAGE_LIMIT);
$tickets = $pageNav->paginateSimple($tickets);
// Creative twist here. Create a new query copying the query criteria, sort, limit,
// and offset. Then join this new query to the $tickets query and clear the
// criteria, sort, limit, and offset from the outer query.
$criteria = clone $tickets;
$criteria->annotations = $criteria->related = $criteria->aggregated = [];
$tickets->constraints = [];
$tickets = $tickets->filter(['ticket_id__in' => $criteria->values_flat('ticket_id')])
->limit(false)->offset(false)->order_by(false);
# Index hint should be used on the $criteria query only
$tickets->clearOption(QuerySet::OPT_INDEX_HINT);
$count = $queue->getCount($thisstaff);
$pageNav->setTotal($count, true);
$pageNav->setURL('tickets.php', $args);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment