[Bps-public-commit] dbix-searchbuilder branch master updated. 1.77-3-g7330d53
BPS Git Server
git at git.bestpractical.com
Wed Jul 5 18:26:42 UTC 2023
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 "dbix-searchbuilder".
The branch, master has been updated
via 7330d53b0f7bf6e1111082fb5eed536fc5d31e07 (commit)
via 3815672c4d341db6a36eed100f04cfce9f332340 (commit)
from 9a475c4f5a83fdf977fe1f6b24d4d4e403d5cd53 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 7330d53b0f7bf6e1111082fb5eed536fc5d31e07
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Jul 6 02:00:56 2023 +0800
Prep version 1.78
diff --git a/Changes b/Changes
index 5d6e61d..f54cf34 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
Revision history for Perl extension DBIx::SearchBuilder.
+1.78 2023-07-05
+ - Query the Count data if current page does not have any records
+ - Require DBD::SQLite 1.60+ for combine searches
+
1.77 2023-06-30
- Change how DistinctQueryAndCount builds query to fix sorting
diff --git a/META.yml b/META.yml
index 22e43c5..aa93498 100644
--- a/META.yml
+++ b/META.yml
@@ -36,4 +36,4 @@ requires:
perl: 5.10.1
resources:
license: http://dev.perl.org/licenses/
-version: '1.77'
+version: '1.78'
diff --git a/lib/DBIx/SearchBuilder.pm b/lib/DBIx/SearchBuilder.pm
index 9a32b5c..636c9d5 100755
--- a/lib/DBIx/SearchBuilder.pm
+++ b/lib/DBIx/SearchBuilder.pm
@@ -4,7 +4,7 @@ package DBIx::SearchBuilder;
use strict;
use warnings;
-our $VERSION = "1.77";
+our $VERSION = "1.78";
use Clone qw();
use Encode qw();
commit 3815672c4d341db6a36eed100f04cfce9f332340
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Jul 6 01:49:10 2023 +0800
Query the Count data if current page does not have any records
When CombineSearchAndCount is enabled, usually we can get both Search
and Count data in a single query. But there could be no search results
given an arbitrary Page number, in which edge case we have to query
again to get Count data.
diff --git a/lib/DBIx/SearchBuilder.pm b/lib/DBIx/SearchBuilder.pm
index 1ccbfd3..9a32b5c 100755
--- a/lib/DBIx/SearchBuilder.pm
+++ b/lib/DBIx/SearchBuilder.pm
@@ -258,7 +258,7 @@ sub __DoSearch {
while ( my $row = $records->fetchrow_hashref() ) {
# search_builder_count_all is from combine search
- if ( !$self->{count_all} && $row->{search_builder_count_all} ) {
+ if ( !defined $self->{count_all} && $row->{search_builder_count_all} ) {
$self->{count_all} = $row->{search_builder_count_all};
}
@@ -317,6 +317,12 @@ sub _DoCount {
return $count_all;
}
+ return $self->__DoCount;
+}
+
+sub __DoCount {
+ my $self = shift;
+
my $QueryString = $self->BuildSelectCountQuery();
my $records = $self->_Handle->SimpleQuery( $QueryString, @{ $self->{_bind_values} || [] } );
return 0 unless $records;
@@ -341,9 +347,13 @@ sub _DoSearchAndCount {
my $QueryString = $self->BuildSelectAndCountQuery();
my $records = $self->_Handle->SimpleQuery( $QueryString, @{ $self->{_bind_values} || [] } );
- $self->{count_all} = 0;
+ undef $self->{count_all};
# __DoSearch updates count_all
my $count = $self->__DoSearch($records);
+
+ # If no results returned, we have to query the count separately.
+ $self->{count_all} //= $self->__DoCount;
+
return ( $count, $self->{count_all} );
}
@@ -1635,7 +1645,7 @@ sub CountAll {
# If we haven't actually got all objects loaded in memory, we
# really just want to do a quick count from the database.
# or if we have paging enabled then we count as well and store it in count_all
- if ( $self->{'must_redo_search'} || ( $self->RowsPerPage && !$self->{'count_all'} ) ) {
+ if ( $self->{'must_redo_search'} || ( $self->RowsPerPage && !defined $self->{'count_all'} ) ) {
# If we haven't already asked the database for the row count, do that
$self->_DoCount;
diff --git a/t/02order.t b/t/02order.t
index 969e1c7..e1eff21 100644
--- a/t/02order.t
+++ b/t/02order.t
@@ -7,7 +7,7 @@ use Test::More;
BEGIN { require "./t/utils.pl" }
our (@AvailableDrivers);
-use constant TESTS_PER_DRIVER => 315;
+use constant TESTS_PER_DRIVER => 363;
my $total = scalar(@AvailableDrivers) * TESTS_PER_DRIVER;
plan tests => $total;
@@ -117,7 +117,7 @@ diag "test ordering objects by object's fields with limit by tags" if $ENV{TEST_
foreach my $direction ( qw(ASC DESC) ) {
foreach my $field ('Name', 'id') {
foreach my $combine_search_and_count ( 0, 1 ) {
-foreach my $per_page (0, 5) {
+foreach my $per_page (0, 5, 30) {
foreach my $page (0, 2) {
my $objs = TestApp::Objects->new($handle);
$objs->CombineSearchAndCount($combine_search_and_count);
-----------------------------------------------------------------------
Summary of changes:
Changes | 4 ++++
META.yml | 2 +-
lib/DBIx/SearchBuilder.pm | 18 ++++++++++++++----
t/02order.t | 4 ++--
4 files changed, 21 insertions(+), 7 deletions(-)
hooks/post-receive
--
dbix-searchbuilder
More information about the Bps-public-commit
mailing list