From 8acd760e5140f9ca5cfcccd17622dfccdfc6e21f Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Fri, 17 Sep 2010 19:04:02 -0300 Subject: [PATCH] Avoid paginating after loading everything. --- app/controllers/my_profile/cms_controller.rb | 20 +++++++++++--------- app/helpers/folder_helper.rb | 9 +++++---- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 9cfc424..7c8c653 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -66,19 +66,21 @@ class CmsController < MyProfileController conditions = ['type != ?', 'RssFeed'] end - @articles = @article.children.find( - :all, - :order => "case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC", - :conditions => conditions - ).paginate(:per_page => per_page, :page => params[:npage]) + @articles = @article.children.paginate( + :order => "case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC", + :conditions => conditions, + :per_page => per_page, + :page => params[:npage] + ) end def index @article = nil - @articles = profile.top_level_articles.find( - :all, - :order => "case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC" - ).paginate(:per_page => per_page, :page => params[:npage]) + @articles = profile.top_level_articles.paginate( + :order => "case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC", + :per_page => per_page, + :page => params[:npage] + ) render :action => 'view' end diff --git a/app/helpers/folder_helper.rb b/app/helpers/folder_helper.rb index 4ca8edd..083fc27 100644 --- a/app/helpers/folder_helper.rb +++ b/app/helpers/folder_helper.rb @@ -4,10 +4,11 @@ module FolderHelper def list_articles(articles, recursive = false) if !articles.blank? - articles = articles.find( - :all, - :order => "updated_at DESC" - ).paginate(:per_page => 10, :page => params[:npage]) + articles = articles.paginate( + :order => "updated_at DESC", + :per_page => 10, + :page => params[:npage] + ) render :file => 'shared/articles_list', :locals => {:articles => articles, :recursive => recursive} else -- libgit2 0.21.2