Forum: Ruby on Rails Why is ruby build in pagination bad?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
525128e48ca2b4c7fb6176ea166fccfd?d=identicon&s=25 Eric G. (gotskill10)
on 2006-10-23 01:26
Hey guys,

Im trying to understand why the ruby pagination is slow and bad so that
I can write a good one of my own.

From my understanding, the ruby paginator, just takes the full results
set and display only the portion that you want it to display.

You then create a paginator object so that Ruby can create pagination
links using the built in helper.

For example, im using ferret multi search with an offset and limit
option. I then use the total_hits() method and make a call for
pagination like this:

   def pages_for(size, options = {})
      default_options = {:per_page => 10}
      options = default_options.merge options
      pages = Paginator.new self, size, options[:per_page],
      (params[:page]||1)
      pages
   end

What is so slow about all this? Where will the slow down be? If you guys
could point me to any good pagination plugins OR even articles about why
the current one sucks that would be great. Thanks in advance!
2f9a03aa0fcfe945229cb6126eda2cb2?d=identicon&s=25 Philip Hallstrom (Guest)
on 2006-10-24 21:03
(Received via mailing list)
> Im trying to understand why the ruby pagination is slow and bad so that
> I can write a good one of my own.
>
> From my understanding, the ruby paginator, just takes the full results
> set and display only the portion that you want it to display.

Yep.  Imagine you have a table with a million rows of data (with a lot
of
text columns).  And you want to page through it ten at a time.  Why
you'd
do this I dunno, but let's just pretend.

To display rows 1-10 Rails is going to return *all* million rows, create
objects for all of them, then hand you back the first 10.  So it's doing
this in SQL: SELECT * FROM big_table

If you create your own pager you can make this a lot more efficient by
doing something like this: SELECT * FROM big_table LIMIT 10 OFFSET 0

And you're only returning 10 rows hwich is going to be a lot faster than
returning 1 million...

-philip
9f0f89bbd9e1ecfbaab6584e429b7a2f?d=identicon&s=25 Josh Susser (jsusser)
on 2006-10-24 21:45
Eric Gross wrote:
> Im trying to understand why the ruby pagination is slow and bad so that
> I can write a good one of my own.
>
> From my understanding, the ruby paginator, just takes the full results
> set and display only the portion that you want it to display.
>
> You then create a paginator object so that Ruby can create pagination
> links using the built in helper.
> ...
> What is so slow about all this? Where will the slow down be? If you guys
> could point me to any good pagination plugins OR even articles about why
> the current one sucks that would be great. Thanks in advance!

How timely...  check out this new paginator gem by Bruce Williams

http://codefluency.com/2006/10/24/paginator-released

--
Josh Susser
http://blog.hasmanythrough.com
3eda6fcd3204ef285fa52176c28c4d3e?d=identicon&s=25 bbqPlate (Guest)
on 2006-10-24 22:38
quick question about size. if i am only dealing with about 1000 items in
my database, is the build in pagination fine?


Philip Hallstrom wrote:
>> Im trying to understand why the ruby pagination is slow and bad so that
>> I can write a good one of my own.
>>
>> From my understanding, the ruby paginator, just takes the full results
>> set and display only the portion that you want it to display.
>
> Yep.  Imagine you have a table with a million rows of data (with a lot
> of
> text columns).  And you want to page through it ten at a time.  Why
> you'd
> do this I dunno, but let's just pretend.
>
> To display rows 1-10 Rails is going to return *all* million rows, create
> objects for all of them, then hand you back the first 10.  So it's doing
> this in SQL: SELECT * FROM big_table
>
> If you create your own pager you can make this a lot more efficient by
> doing something like this: SELECT * FROM big_table LIMIT 10 OFFSET 0
>
> And you're only returning 10 rows hwich is going to be a lot faster than
> returning 1 million...
>
> -philip
0900e6a4828bd989f96427082c6c74ca?d=identicon&s=25 Mike Garey (random52k)
on 2006-10-24 22:54
(Received via mailing list)
also be sure to check out paginating_find
(http://cardboardrocket.com/2006/09/06/paginating-f...).
I like the way it overloads the regular find method.

Mike
525128e48ca2b4c7fb6176ea166fccfd?d=identicon&s=25 Eric G. (gotskill10)
on 2006-10-25 02:29
Hmm, isnt this just using limit and offset to get only a section of your
result set and then putting the TOTAL_RESULTS variable to know how many
pages there are?

It uses the Paginator class which already comes with Ruby right.

Also, if im paginating less then like 7 or 8 pages, do I really have to
worry about  pagination efficiency? I mean Im going to query a result
set of like 70 or 80 and then break it up into pages, is that really
something i have to get a sexy paginator over?


>
> How timely...  check out this new paginator gem by Bruce Williams
>
> http://codefluency.com/2006/10/24/paginator-released
>
> --
> Josh Susser
> http://blog.hasmanythrough.com
3a0f2ec009ceffdd65f056540a409a23?d=identicon&s=25 Chris Mear (Guest)
on 2006-10-25 10:46
(Received via mailing list)
Eric Gross wrote:
> Im trying to understand why the ruby pagination is slow and bad so that
> I can write a good one of my own.
>
> From my understanding, the ruby paginator, just takes the full results
> set and display only the portion that you want it to display.

Nope, the built-in Rails paginator uses offset and limit to fetch only
the results for the current page.

According to this page:

http://glu.ttono.us/articles/2006/08/30/on-the-days-events

it's not the database-level stuff that's the problem, but the
view-level pagination helpers that have 'efficiency issues'. I haven't
been able to find a more detailed explanation, though.

Anyone care to enlighten us?

Chris
This topic is locked and can not be replied to.