[Dbix-class] extended paging

Rodrigo rodrigolive at gmail.com
Tue Dec 1 01:33:04 GMT 2009


On Mon, Nov 30, 2009 at 11:17 PM, Matija Grabnar <matija at serverflow.com>wro=
te:

> I don't think you'll find a way to use the builtin paging functions if you
> later throw some rows away.
> You'll have to do the paging by hand. It's even worse than that: The way
> you have things set up,
> if you want to show page 100, you won't know where it starts unless you
> parse ALL the rows in the
> preceding 99 pages. It will work if you only get a few pages usually, but
> if you get high page numbers,
> the whole thing will collapse.
>
>
Ideally, I think the paging algorithm somewhere should handle a callback
filter sub and be able to fetch a few more rows (until a page is completed),
in case the filter dropped. Well, something in the lines:

sub filter_callback {
    my $row =3D shift;
    return $c->localize( $row->title ) =3D~ /$title_filter/i;
}
my $rs =3D ...->search(undef, { page=3D>1, rows=3D>20,
paging_callback=3D>\&filter_callback });

But I don't think implementing this is that trivial. The search-and-page
algorithm would have to fetch the 20 rows, filter them out, and if there
were rows thrown-out, fetch a few more, filter again... until a full 20 row
page is complete (or the data set has been exhausted).

At worst case, all million CD table rows are read and thrown out, which
could result in a performance loss, but a working paging algorithm.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20091201/3c0=
9c0a8/attachment.htm


More information about the DBIx-Class mailing list