Implement filter limits. Which go before pagination/advanced search limits

This commit is contained in:
Isaac Connor 2022-02-02 10:49:05 -05:00
parent 4874dedc1f
commit 31eff49a46
1 changed files with 12 additions and 1 deletions

View File

@ -187,6 +187,9 @@ function queryRequest($filter, $search, $advsearch, $sort, $offset, $order, $lim
$col_str = 'E.*, M.Name AS Monitor'; $col_str = 'E.*, M.Name AS Monitor';
$sql = 'SELECT ' .$col_str. ' FROM `Events` AS E INNER JOIN Monitors AS M ON E.MonitorId = M.Id'.$where.($sort?' ORDER BY '.$sort.' '.$order:''); $sql = 'SELECT ' .$col_str. ' FROM `Events` AS E INNER JOIN Monitors AS M ON E.MonitorId = M.Id'.$where.($sort?' ORDER BY '.$sort.' '.$order:'');
if ($filter->limit() and !count($filter->pre_sql_conditions()) and !count($filter->post_sql_conditions())) {
$sql .= ' LIMIT '.$filter->limit();
}
$storage_areas = ZM\Storage::find(); $storage_areas = ZM\Storage::find();
$StorageById = array(); $StorageById = array();
@ -213,6 +216,12 @@ function queryRequest($filter, $search, $advsearch, $sort, $offset, $order, $lim
$unfiltered_rows[] = $row; $unfiltered_rows[] = $row;
} # end foreach row } # end foreach row
# Filter limits come before pagination limits.
if ($filter->limit() and ($filter->limit() > count($unfiltered_rows))) {
ZM\Debug("Filtering rows due to filter->limit " . count($unfiltered_rows)." limit: ".$filter->limit());
$unfiltered_rows = array_slice($unfiltered_rows, 0, $filter->limit());
}
ZM\Debug('Have ' . count($unfiltered_rows) . ' events matching base filter.'); ZM\Debug('Have ' . count($unfiltered_rows) . ' events matching base filter.');
$filtered_rows = null; $filtered_rows = null;
@ -251,8 +260,10 @@ function queryRequest($filter, $search, $advsearch, $sort, $offset, $order, $lim
$filtered_rows = $unfiltered_rows; $filtered_rows = $unfiltered_rows;
} # end if search_filter->terms() > 1 } # end if search_filter->terms() > 1
if ($limit) if ($limit) {
ZM\Debug("Filtering rows due to limit " . count($filtered_rows)." offset: $offset limit: $limit");
$filtered_rows = array_slice($filtered_rows, $offset, $limit); $filtered_rows = array_slice($filtered_rows, $offset, $limit);
}
$returned_rows = array(); $returned_rows = array();
foreach ($filtered_rows as $row) { foreach ($filtered_rows as $row) {