[Dbix-class] paging question
James Marca
jmarca at translab.its.uci.edu
Wed Feb 3 23:01:22 GMT 2010
On Wed, Feb 03, 2010 at 11:14:28PM +0100, demerphq wrote:
> On 2 February 2010 20:58, James Marca <jmarca at translab.its.uci.edu> wrote:
> > On Tue, Feb 02, 2010 at 11:14:27AM -0800, James Marca wrote:
> >> Hi.
> >>
> >> First DBIx::Class is excellent and kudos all around.
> >>
> >> I have recently needed to use the paging feature for the first time
> >> and I'm not sure of the best way to do this.
> >>
> >> First a simple question: How should one terminate the paging? Is
> >> there some variable to check to find out how many pages of data are
> >> expected from a result set? I couldn't find anything in the docs,
> >> but I probably missed it.
> >
> > Clarifying my question... I am aware of the ability to call
> >
> > my $data_page_object = $rs->pager();
> > my $total_count = $data_page_object->total_entries();
> >
> > But that looks like it will hit the database once with a count(*)
> > select call, which in PostgreSQL is expensive. What I am hoping for
> > is something along the lines of
> >
> > my $paged_rs = $rs->page($nextpage);
> > if (! $paged_rs || ! $paged_rs->no_more_data ){
> > return;
> > # undefined page result set means I've gone beyond the max pages
> > # while calling $paged_rs->first would hit the db with that
> > # expensive query
> > }
> >
> > No, I have no idea how to get that result without asking for it
> > explicitly from the db, but just because I can't figure that out
> > doesn't mean it is impossible!
>
> Ive implemented this type of thing outside of DBIx by limiting the
> query to one more record than I intend to page.
>
> This works nicely as it does two things. First it gives me a flag
> which i can use to decide whether a page need a "show next page link",
> and it gives me an item that i can use to prekey the paging so it does
> NOT use the offset/limit form, and instead uses the id of the flag
> record to do an indexed search from where the next page starts.
>
Ah, very clever hack!
James
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
More information about the DBIx-Class
mailing list