Skip Menu |
 

This queue is for tickets about the DBIx-Class CPAN distribution.

Report information
The Basics
Id: 49014
Status: rejected
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: jonathanrbaker [...] yahoo.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.08108
Fixed in: (no value)



Subject: FYI: order_by => \'RAND()' and cursor reset (kills STH) is bad
Download (untitled) / with headers
text/plain 582b
(using MySQL as database) Create a result set and use order_by => \'RAND()' (random order). Grab a page of results and use the rows. Reset the cursor for this page and loop through the page's rows a few times. Get random results each time. Ha ha ha. :) Looking in DBIx::Class::Storage::DBI::Cursor it seems the "reset" method is killing the STH. Perhaps this should be warned about in the cursor documentation? Bonus points, is there another way to reset the cursor that that will keep the original STH and its original random batch of rows? Thanks for all the hard work!
On Wed Aug 26 01:42:31 2009, jrbaker wrote: Show quoted text
> (using MySQL as database) > > Create a result set and use order_by => \'RAND()' (random order). > Grab a page of results and use the rows. > > Reset the cursor for this page > and loop through the page's rows a few times. > Get random results each time. Ha ha ha. :) > > Looking in DBIx::Class::Storage::DBI::Cursor > it seems the "reset" method is killing the STH. > > Perhaps this should be warned about in the cursor documentation? > Bonus points, is there another way to reset the cursor that > that will keep the original STH and its original random batch of rows? >
There isn't any other way, because the cursor *IS* the $sth. There is no intermediate data store which can be rewound back and forth. What you want in this case is http://search.cpan.org/~ribasushi/DBIx-Class-0.08109/lib/DBIx/Class/ResultSet.pm#cache Nevertheless I'd welcome a doc patch to ResultSet::reset() explaining what does it actually do, thus keeping the bugreport open for the time being.
Download (untitled) / with headers
text/plain 870b
On Wed Aug 26 02:58:44 2009, RIBASUSHI wrote: Show quoted text
> On Wed Aug 26 01:42:31 2009, jrbaker wrote:
>>>SNIP<<<
> > Perhaps this should be warned about in the cursor documentation? > > Bonus points, is there another way to reset the cursor that > > that will keep the original STH and its original random batch of
> rows?
> >
> > There isn't any other way, because the cursor *IS* the $sth. There is > no > intermediate data store which can be rewound back and forth. What you > want in this case is > http://search.cpan.org/~ribasushi/DBIx-Class- > 0.08109/lib/DBIx/Class/ResultSet.pm#cache > > Nevertheless I'd welcome a doc patch to ResultSet::reset() explaining > what does it actually do, thus keeping the bugreport open for the time > being.
Duh! There is no spoon! I'll use { cache => 1 } for now and look into the cache examples. Thanks again for the quick response!
Download (untitled) / with headers
text/plain 119b
Rejected as non-bug. Please reopen ticket if you find the time to write a documentation patch explaining the situation.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.