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! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
> 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> > 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! > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
random52k-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-24 20:51 UTC
Re: Why is ruby build in pagination bad?
also be sure to check out paginating_find (http://cardboardrocket.com/2006/09/06/paginating-find-now-even-sexier/). I like the way it overloads the regular find method. Mike --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---