[Bps-public-commit] dbix-searchbuilder branch, master, updated. 1.63_01-51-ge0166ef

Thomas Sibley trs at bestpractical.com
Thu May 16 00:26:07 EDT 2013


The branch, master has been updated
       via  e0166ef0d8131abd97d32d618f28963bb695ed8f (commit)
       via  719d92bdf8924b44ff685274297145fd898bd058 (commit)
       via  becafc713fb28e061f3d53425e493bcd166e6364 (commit)
      from  92483200eec17368e433e36d3d9ab0fc08376024 (commit)

Summary of changes:
 lib/DBIx/SearchBuilder.pm | 11 ++++++++---
 t/01searches.t            |  8 +++++++-
 2 files changed, 15 insertions(+), 4 deletions(-)

- Log -----------------------------------------------------------------
commit becafc713fb28e061f3d53425e493bcd166e6364
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Wed May 15 17:18:57 2013 -0700

    Failing tests demonstrating a bug in ->Last introduced by d97c291

diff --git a/t/01searches.t b/t/01searches.t
index b875240..83a2001 100644
--- a/t/01searches.t
+++ b/t/01searches.t
@@ -7,7 +7,7 @@ use Test::More;
 BEGIN { require "t/utils.pl" }
 our (@AvailableDrivers);
 
-use constant TESTS_PER_DRIVER => 149;
+use constant TESTS_PER_DRIVER => 150;
 
 my $total = scalar(@AvailableDrivers) * TESTS_PER_DRIVER;
 plan tests => $total;
@@ -440,6 +440,12 @@ SKIP: {
         ok $u->{fetched}{"\L$_"}, "fetched normal field $_" for keys %{$u->_ClassAccessible};
     }
 
+    # Last without running the search first
+    $users_obj = TestApp::Users->new( $handle );
+    $users_obj->UnLimit;
+    $users_obj->OrderBy( FIELD => "Login", ORDER => "ASC" );
+    is $users_obj->Last->Login, "obra", "Found last record correctly before search was run";
+
 	cleanup_schema( 'TestApp', $handle );
 }} # SKIP, foreach blocks
 

commit 719d92bdf8924b44ff685274297145fd898bd058
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Wed May 15 17:21:38 2013 -0700

    Return the correct record from ->Last instead of, since d97c291, the first record
    
    When ->Last is called on a collection before the search is actually run,
    the item iterator set by Last is based on a count query
    (opportunistically run by ->Count when the actual results haven't been
    fetched yet).  ->Next is then called, and the actual search query is
    run.  Since d97c291, running the search query resets the item iterator,
    effectively causing Last to return the first record when called under
    these very particular circumstances.  Restore the proper behaviour of
    Last by running the search query if necessary before inspecting the item
    count and setting the item iterator.
    
    This change also closes a race condition that occurs when the matching
    records change between running the count query and the full query.  When
    results have already been fetched, ->Count will not run another query
    but simply return the number of fetched results.  This keeps the object
    internally consistent.

diff --git a/lib/DBIx/SearchBuilder.pm b/lib/DBIx/SearchBuilder.pm
index 658a8f2..859f29e 100755
--- a/lib/DBIx/SearchBuilder.pm
+++ b/lib/DBIx/SearchBuilder.pm
@@ -574,6 +574,7 @@ Returns the last item
 
 sub Last {
     my $self = shift;
+    $self->_DoSearch if $self->{'must_redo_search'};
     $self->GotoItem( ( $self->Count ) - 1 );
     return ( $self->Next );
 }

commit e0166ef0d8131abd97d32d618f28963bb695ed8f
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Wed May 15 21:25:26 2013 -0700

    Document the caveat of using GotoItem with a non-zero N

diff --git a/lib/DBIx/SearchBuilder.pm b/lib/DBIx/SearchBuilder.pm
index 859f29e..3987e3a 100755
--- a/lib/DBIx/SearchBuilder.pm
+++ b/lib/DBIx/SearchBuilder.pm
@@ -538,9 +538,13 @@ sub GotoFirstItem {
 
 =head2 GotoItem
 
-Takes an integer, n.
-Sets the record counter to n. the next time you call Next,
-you'll get the nth item.
+Takes an integer N and sets the record iterator to N.  The first time L</Next>
+is called afterwards, it will return the Nth item found by the search.
+
+You should only call GotoItem after you've already fetched at least one result
+or otherwise forced the search query to run (such as via L</ItemsArrayRef>).
+If GotoItem is called before the search query is ever run, it will reset the
+item iterator and L</Next> will return the L</First> item.
 
 =cut
 

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



More information about the Bps-public-commit mailing list