From: Peter Rabbitson Date: Mon, 18 May 2009 17:32:42 +0000 (+0000) Subject: pager optimization X-Git-Tag: v0.08103~64^2~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=132bc9dc0c1b5fe97dfb4750360ab414fa1250f5;p=dbsrgits%2FDBIx-Class.git pager optimization --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 932d16f..cc87db1 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1708,6 +1708,9 @@ C on the L object. sub pager { my ($self) = @_; + + return $self->{pager} if $self->{pager}; + my $attrs = $self->{attrs}; $self->throw_exception("Can't create pager for non-paged rs") unless $self->{attrs}{page}; @@ -1717,10 +1720,13 @@ sub pager { # with a subselect) to get the real total count my $count_attrs = { %$attrs }; delete $count_attrs->{$_} for qw/rows offset page pager/; - my $total_count = (ref $self)->new($self->result_source, $count_attrs); + my $total_count = (ref $self)->new($self->result_source, $count_attrs)->count; - return $self->{pager} ||= Data::Page->new( - $total_count, $attrs->{rows}, $self->{attrs}{page}); + return $self->{pager} = Data::Page->new( + $total_count, + $attrs->{rows}, + $self->{attrs}{page} + ); } =head2 page