From: Peter Rabbitson Date: Sat, 30 Apr 2011 00:43:30 +0000 (+0200) Subject: Revert incorrect assumption about non-functional cached pagers 65245220 X-Git-Tag: v0.08191~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=74719352f7e25d81f00de886daa77094ce3289f8;p=dbsrgits%2FDBIx-Class.git Revert incorrect assumption about non-functional cached pagers 65245220 While on the surface it seems logical that a cached resultset is inherently non-pageable, one has to remember that search chaining with different arguments (i.e. different offset) fires a new query, not subject to the existing resultset cache. --- diff --git a/Changes b/Changes index ddea653..69b553d 100644 --- a/Changes +++ b/Changes @@ -38,6 +38,8 @@ Revision history for DBIx::Class - Fix older oracle-specific "WhereJoins" to work properly with name quoting - Fix problems with M.A.D. under CGI::SpeedyCGI (RT#65131) + - Reenable paging of cached resultsets - breakage erroneously added + in 0.08127 - Better error handling when prepare() fails silently - Fixes skipped lines when a comment is followed by a statement when deploying a schema via sql file diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 089972e..7e5a850 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -2157,10 +2157,6 @@ sub pager { return $self->{pager} if $self->{pager}; - if ($self->get_cache) { - $self->throw_exception ('Pagers on cached resultsets are not supported'); - } - my $attrs = $self->{attrs}; if (!defined $attrs->{page}) { $self->throw_exception("Can't create pager for non-paged rs"); diff --git a/t/67pager.t b/t/67pager.t index 1835d6d..b7eb2ca 100644 --- a/t/67pager.t +++ b/t/67pager.t @@ -152,19 +152,31 @@ is ($qcnt, 0, 'No queries with explicitly sey total count'); # test cached resultsets my $init_cnt = $rs->count; -$it = $rs->search({}, { rows => 3, cache => 1 })->page(3); +$it = $rs->search({}, { rows => 3, cache => 1 })->page(2); +is ($it->count, 3, '3 rows'); +is (scalar $it->all, 3, '3 objects'); + +isa_ok($it->pager,'Data::Page','Get a pager back ok'); +is($it->pager->total_entries,7); +is($it->pager->current_page,2); +is($it->pager->entries_on_this_page,3); + +$it = $it->page(3); is ($it->count, 1, 'One row'); is (scalar $it->all, 1, 'One object'); +isa_ok($it->pager,'Data::Page','Get a pager back ok'); +is($it->pager->total_entries,7); +is($it->pager->current_page,3); +is($it->pager->entries_on_this_page,1); + + $it->delete; is ($rs->count, $init_cnt - 1, 'One row deleted as expected'); is ($it->count, 1, 'One row (cached)'); is (scalar $it->all, 1, 'One object (cached)'); -throws_ok { $it->pager } - qr/Pagers on cached resultsets are not supported/, 'No pagers on cached resultsets'; - # test fresh rs creation with modified defaults my $p = sub { $schema->resultset('CD')->page(1)->pager->entries_per_page; };