Mailing List Archive

rt branch 5.0/combine-search-and-count created. rt-5.0.3-338-g67a3fe2a25
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/combine-search-and-count has been created
at 67a3fe2a2529064172e061b32c96992ea563bffc (commit)

- Log -----------------------------------------------------------------
commit 67a3fe2a2529064172e061b32c96992ea563bffc
Author: sunnavy <sunnavy@bestpractical.com>
Date: Thu Jan 12 04:17:03 2023 +0800

Combine search and count for saved searches on dashboards if possible

diff --git a/share/html/Elements/ShowSearch b/share/html/Elements/ShowSearch
index c6f4f4ea76..4fd8555c4d 100644
--- a/share/html/Elements/ShowSearch
+++ b/share/html/Elements/ShowSearch
@@ -195,6 +195,23 @@ if ($ShowCount) {
}

$collection->FromSQL($query);
+ if ( $ProcessedSearchArg->{OrderBy} ) {
+ my @order_by;
+ my @order;
+ if ( $ProcessedSearchArg->{OrderBy} =~ /\|/ ) {
+ @order_by = split /\|/, $ProcessedSearchArg->{OrderBy};
+ @order = split /\|/, $ProcessedSearchArg->{Order};
+ }
+ else {
+ @order_by = $ProcessedSearchArg->{OrderBy};
+ @order = $ProcessedSearchArg->{Order};
+ }
+ @order_by = grep length, @order_by;
+ $collection->OrderByCols( map { { FIELD => $order_by[$_], ORDER => $order[$_] } } ( 0 .. $#order_by ) );
+ }
+ $collection->RowsPerPage( $ProcessedSearchArg->{Rows} ) if $ProcessedSearchArg->{Rows};
+ $collection->CombineSearchAndCount(1);
+
my $count = $collection->CountAll();

my $title;

commit 237a4330b56eea66818e4cb0b851440e03700712
Author: sunnavy <sunnavy@bestpractical.com>
Date: Sat Aug 27 01:12:45 2022 +0800

Combine search and count for search result pages if possible

This commit also fixes the handling of $OrderBy on search result page to
exclude empty values, to make combined SQL work: search result page
calls CountAll only, of which SQL doesn't include the "ORDER BY ..."
part, the issue wouldn't be exposed without combined SQL.

To make sure the combined search returns the demanded resultset, we need
to call CountAll after all setups like OrderByCols, RowsPerPage, etc.

diff --git a/share/html/Elements/CollectionList b/share/html/Elements/CollectionList
index 745c764288..3fb23f8b8f 100644
--- a/share/html/Elements/CollectionList
+++ b/share/html/Elements/CollectionList
@@ -66,19 +66,6 @@ elsif (!$Collection && $Class eq 'RT::Assets') {
# dashboard mail can be suppressed if there are no results
$$HasResults = 0 if $HasResults && !defined($$HasResults);

-$TotalFound = $Collection->CountAll() unless defined $TotalFound;
-return '' if !$TotalFound && !$ShowEmpty;
-
-if ( $Rows ) {
- if ( $TotalFound <= $Rows ) {
- $Page = 1;
- }
- else {
- my $MaxPage = int( $TotalFound / $Rows ) + ( $TotalFound % $Rows ? 1 : 0 );
- $Page = $MaxPage if $Page > $MaxPage;
- }
-}
-
# XXX: ->{'order_by'} is hacky, but there is no way to check if
# collection is ordered or not
if ( @OrderBy && ($AllowSorting || $PreferOrderBy || !$Collection->{'order_by'}) ) {
@@ -97,6 +84,24 @@ $Collection->RowsPerPage( $Rows ) if $Rows;
$Page = 1 unless $Page && $Page > 0; # workaround problems with $Page = '' or undef
$Collection->GotoPage( $Page - 1 ); # SB uses page 0 as the first page

+$Collection->CombineSearchAndCount(1) if $Collection->can('CombineSearchAndCount');
+$TotalFound = $Collection->CountAll() unless defined $TotalFound;
+return '' if !$TotalFound && !$ShowEmpty;
+
+# Adjust page after CountAll, otherwise $TotalFound could be not defined.
+# On the other hand, CountAll needs page info if it's a combined search,
+# thus we have to set page first and then adjust it here.
+if ( $Rows ) {
+ if ( $TotalFound <= $Rows ) {
+ $Page = 1;
+ }
+ else {
+ my $MaxPage = int( $TotalFound / $Rows ) + ( $TotalFound % $Rows ? 1 : 0 );
+ $Page = $MaxPage if $Page > $MaxPage;
+ }
+}
+$Collection->GotoPage( $Page - 1 );
+
# DisplayFormat lets us use a "temporary" format for display, while
# still using our original format for next/prev page links.
# bulk update uses this feature to add checkboxes
diff --git a/share/html/Search/Results.html b/share/html/Search/Results.html
index f39664fbf6..e0901d8f92 100644
--- a/share/html/Search/Results.html
+++ b/share/html/Search/Results.html
@@ -62,6 +62,7 @@

<& /Elements/CollectionList,
Query => $Query,
+ Collection => $session{$session_name},
TotalFound => $count,
AllowSorting => 1,
AllowFiltering => 1,
@@ -201,13 +202,14 @@ if ($OrderBy =~ /\|/) {
my @OrderBy = split /\|/,$OrderBy;
my @Order = split /\|/,$Order;
$session{$session_name}->OrderByCols(
- map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } } ( 0
- .. $#OrderBy ) );;
+ map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } }
+ grep { $OrderBy[$_] } ( 0 .. $#OrderBy ) );
} else {
$session{$session_name}->OrderBy(FIELD => $OrderBy, ORDER => $Order);
}
$session{$session_name}->RowsPerPage( $Rows ) if $Rows;
$session{$session_name}->GotoPage( $Page - 1 );
+$session{$session_name}->CombineSearchAndCount(1);

$session{$hash_name} = {
Format => $Format,

commit 6b9e944e8c78e110a82be0c07d2c23654c3ba165
Author: sunnavy <sunnavy@bestpractical.com>
Date: Sat Mar 25 05:04:01 2023 +0800

Require DBIx::SearchBuilder 1.73+ to support CombineSearchAndCount

diff --git a/etc/cpanfile b/etc/cpanfile
index 31ebaf9ce4..0992469931 100644
--- a/etc/cpanfile
+++ b/etc/cpanfile
@@ -22,7 +22,7 @@ requires 'DateTime', '>= 0.44';
requires 'DateTime::Format::Natural', '>= 0.67';
requires 'DateTime::Locale', '>= 0.40, != 1.00, != 1.01';
requires 'DBI', '>= 1.37';
-requires 'DBIx::SearchBuilder', '>= 1.71';
+requires 'DBIx::SearchBuilder', '>= 1.73';
requires 'Devel::GlobalDestruction';
requires 'Devel::StackTrace', '>= 1.19, != 1.28, != 1.29';
requires 'Digest::base';

-----------------------------------------------------------------------


hooks/post-receive
--
rt
_______________________________________________
rt-commit mailing list
rt-commit@lists.bestpractical.com
https://lists.bestpractical.com/mailman/listinfo/rt-commit