While using the pagination helper and creating a search function I noticed that I had to perform 2 queries. The first query to get a count the number of records and a second query for the actual page of results. My thought is would it be more efficient to simply grab the message with the first query and then in some way filter the results for the actual page? In WebObjects I could create a "qualifier" to apply to an array or use kvc to select a subset of the results. Sorry if I may be pulling a noob move here since I am still shaking the java/wo mindset. I would love to here any thoughts on this. -- Lon Baker
On Thu, 2005-01-13 at 23:32 -0500, Lon Baker wrote:> While using the pagination helper and creating a search function I > noticed that I had to perform 2 queries. The first query to get a count > the number of records and a second query for the actual page of > results.When I recently used it, my concern wasn''t so much the 2 queries since the first one should most of the time be a index scan and filter to then only transfer a count. My concern really was the need to either create 2 model functions for each query that was paginated or to move some of the query into the controller. I am not too happy with the SQL in controller idea as it breaks down the proper MVC roles. I am not too happy with 2 functions in the model as it adds some repeating.> My thought is would it be more efficient to simply grab the message > with the first query and then in some way filter the results for the > actual page?Efficient would be dependent on a case by case basis. If you only have 100-200 records or less to be displayed, it might not matter if you pulled the full record set or if you let the DB do the filtering. However, if you have a few thousand records to be displayed, letting the DB do the filtering lets you reduce memory needs and reduces the on the wire transfer to just what is necessary. I feel it is more likely to be necessary to let the DB do the filtering in most cases. So maybe it would be good to show a better example of how to use the pagination code that shows a more advanced query and the way to put all of the query into the model and none in the controller. For example, is there a way to set up in the model a count method on a find_all method? That would reduce the extra code writing and potential for problems when something changes. -- Steven Critchfield <critch-wQLwMjUOumVBDgjK7y7TUQ@public.gmane.org>
I don''t understand your problem. My code typicall looks like this: def list @audit_pages, @audits paginate :audit, :order_by => "created_at DESC", :per_page => 12 end And the view contains <% if @user_pages %> User <%= @user_pages.current.first_item %> - <%= @user_pages.current.last_item %> of <%= @user_pages.item_count %> users <%= link_to(h(''Previous''), @user_pages.current.previous.to_link) + " | " if @user_pages.current.previous %> <%= @user_pages.basic_html(self, 4) %> <%= " | " + link_to(h(''Next''), @user_pages.current.next.to_link) if @user_pages.current.next %> <% end %> So, I don''t see 2 queries. -----Ursprungliche Nachricht----- Von: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]Im Auftrag von Lon Baker Gesendet: Freitag, 14. Januar 2005 05:32 An: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Betreff: [Rails] Pagination Helper Thoughts While using the pagination helper and creating a search function I noticed that I had to perform 2 queries. The first query to get a count the number of records and a second query for the actual page of results. My thought is would it be more efficient to simply grab the message with the first query and then in some way filter the results for the actual page? In WebObjects I could create a "qualifier" to apply to an array or use kvc to select a subset of the results. Sorry if I may be pulling a noob move here since I am still shaking the java/wo mindset. I would love to here any thoughts on this. -- Lon Baker _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
I don''t understand your problem. My code typically looks like this: def list @audit_pages, @audits paginate :audit, :order_by => "created_at DESC", :per_page => 12 end And the view contains <% if @audit_pages %> Audit <%= @audit_pages.current.first_item %> - <%= @audit_pages.current.last_item %> of <%= @audit_pages.item_count %> audits <%= link_to(h(''Previous''), @audit_pages.current.previous.to_link) + " | " if @audit_pages.current.previous %> <%= @audit_pages.basic_html(self, 4) %> <%= " | " + link_to(h(''Next''), @audit_pages.current.next.to_link) if @audit_pages.current.next %> <% end %> So, I don''t see 2 queries. -----Ursprungliche Nachricht----- Von: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]Im Auftrag von Lon Baker Gesendet: Freitag, 14. Januar 2005 05:32 An: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Betreff: [Rails] Pagination Helper Thoughts While using the pagination helper and creating a search function I noticed that I had to perform 2 queries. The first query to get a count the number of records and a second query for the actual page of results. My thought is would it be more efficient to simply grab the message with the first query and then in some way filter the results for the actual page? In WebObjects I could create a "qualifier" to apply to an array or use kvc to select a subset of the results. Sorry if I may be pulling a noob move here since I am still shaking the java/wo mindset. I would love to here any thoughts on this. -- Lon Baker _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails