TT#61559 TT#61752 apply orderby to datatable setop queries

for panel UI datatables such as callhistory, automatic rowcount
clipping comes into effect, to prevent pageloads taking minutes
with large calllists.

the clipping also requires special handling of any queries
with an OR clause, which we explicitly expressed as compound
queries (set operations eg. UNION) meanwhile (fortunately!).
this allows to improve the query speed in such cases, by injecting
the filter condition to each subset query.

when introducing this technique, it was clear to sacrifice
ordering of the result, since sorting is pointless when merging
clipped subsets with UNION. allthoug the UI provides a subtle
hint whenever clipping occurs, this is not intuitive to users
(what else).

this is an attempt to improve the situation by applying the
order clauses to the subsets. this way eg. the initial sorting
(timestamp descending) of the callhistory datatable should show the
recent items properly and effectively clip away the older entries.

Change-Id: Ia249e96ac4330cfcdb4905ce2cd0b925aace80f4
changes/12/31112/8
Rene Krenn 7 years ago
parent 856cc68e88
commit 0c93d71e90

@ -100,6 +100,7 @@ sub process {
# sorting
my $sortColumn = $c->request->params->{iSortCol_0};
my $sortDirection = $c->request->params->{sSortDir_0} || 'asc';
my $sortName;
if(defined $sortColumn && defined $sortDirection && ! $use_rs_cb) {
if('desc' eq lc $sortDirection) {
$sortDirection = 'desc';
@ -115,7 +116,7 @@ sub process {
push @displayedFields, $name;
}
# ... and pick the name defined by the dt index
my $sortName = $displayedFields[$sortColumn];
$sortName = $displayedFields[$sortColumn];
$rs = $rs->search(undef, {
order_by => {
@ -143,6 +144,9 @@ sub process {
my ($stmt, @bind_vals) = @{${$totalRecords_rs->as_query}};
($is_set_operations,$stmt) = _limit_set_queries($stmt,sub {
my $part_stmt = shift;
if ($sortName) {
$part_stmt .= ' order by ' . $sortName . ' ' . $sortDirection;
}
return $part_stmt . ' limit ' . $params->{count_limit};
});
@bind_vals = map { $_->[1]; } @bind_vals;
@ -160,6 +164,13 @@ sub process {
result_class => $rs->result_class,
});
$rs = _resolve_joins($rs,$cols);
if ($sortName) {
$rs = $rs->search(undef, {
order_by => {
"-$sortDirection" => $sortName,
}
});
}
}
$rs = $rs->search(undef, {
offset => $pageStart,

Loading…
Cancel
Save