From ee1a70033ca9f46891538653fa3a93fafb500fd5 Mon Sep 17 00:00:00 2001 From: albert Date: Fri, 22 Mar 2013 21:18:13 -0400 Subject: [PATCH] fix counts --- app/controllers/posts_controller.rb | 2 +- app/logical/post_sets/favorite.rb | 9 +++++++-- app/logical/post_sets/note.rb | 9 ++++++++- app/logical/post_sets/pool.rb | 2 +- app/logical/post_sets/popular.rb | 2 +- app/models/forum_post.rb | 2 +- app/models/forum_topic.rb | 2 +- lib/danbooru/paginator/active_record_extension.rb | 2 +- 8 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index e7de7239a..95cbbc76c 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -8,7 +8,7 @@ class PostsController < ApplicationController rescue_from ActiveRecord::RecordNotFound, :with => :rescue_exception def index - @post_set = PostSets::Post.new(tag_query, params[:page], params[:limit]) + @post_set = PostSets::Post.new(tag_query, params[:page], params[:limit] || CurrentUser.user.per_page) @posts = @post_set.posts respond_with(@posts) do |format| format.atom diff --git a/app/logical/post_sets/favorite.rb b/app/logical/post_sets/favorite.rb index 404ade35a..b0d051260 100644 --- a/app/logical/post_sets/favorite.rb +++ b/app/logical/post_sets/favorite.rb @@ -1,10 +1,15 @@ module PostSets class Favorite < Base - attr_reader :user, :page, :favorites + attr_reader :user, :page, :favorites, :params def initialize(user_id, page = 1, params = {}) + @params = params @user = ::User.find(user_id) - @favorites = ::Favorite.for_user(user.id).paginate(page, :limit => params[:limit]).order("favorites.id desc") + @favorites = ::Favorite.for_user(user.id).paginate(page, :limit => limit).order("favorites.id desc") + end + + def limit + params[:limit] || CurrentUser.user.per_page end def tag_array diff --git a/app/logical/post_sets/note.rb b/app/logical/post_sets/note.rb index ce84c1626..5e10cc204 100644 --- a/app/logical/post_sets/note.rb +++ b/app/logical/post_sets/note.rb @@ -1,10 +1,17 @@ module PostSets class Note < Post + attr_reader :params + def initialize(params) # don't call super because we don't want to repeat these queries + @params = params @tag_array = Tag.scan_query(params[:tags]) @page = params[:page] || 1 - @posts = ::Post.tag_match(tag_string).has_notes.paginate(page, :limit => params[:limit]).reorder("last_noted_at desc") + @posts = ::Post.tag_match(tag_string).has_notes.paginate(page, :limit => limit).reorder("last_noted_at desc") + end + + def limit + params[:limit] || CurrentUser.user.per_page end end end diff --git a/app/logical/post_sets/pool.rb b/app/logical/post_sets/pool.rb index e80670fa5..29ecf22d7 100644 --- a/app/logical/post_sets/pool.rb +++ b/app/logical/post_sets/pool.rb @@ -16,7 +16,7 @@ module PostSets end def limit - Danbooru.config.posts_per_page + CurrentUser.user.per_page end def tag_array diff --git a/app/logical/post_sets/popular.rb b/app/logical/post_sets/popular.rb index 0950abf6b..aa8720809 100644 --- a/app/logical/post_sets/popular.rb +++ b/app/logical/post_sets/popular.rb @@ -12,7 +12,7 @@ module PostSets end def limit - 25 + CurrentUser.user.per_page end def min_date diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index 1c65a1f3d..0a239d6ce 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -120,7 +120,7 @@ class ForumPost < ActiveRecord::Base end def forum_topic_page - ((ForumPost.where("topic_id = ? and created_at <= ?", topic_id, created_at).count) / CurrentUser.user.per_page.to_f).ceil + ((ForumPost.where("topic_id = ? and created_at <= ?", topic_id, created_at).count) / Danbooru.config.posts_per_page.to_f).ceil end def is_original_post? diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index a82c8ac86..c78e0b4e8 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -56,7 +56,7 @@ class ForumTopic < ActiveRecord::Base end def last_page - (posts.count / CurrentUser.user.per_page.to_f).ceil + (posts.count / Danbooru.config.posts_per_page.to_f).ceil end def presenter(forum_posts) diff --git a/lib/danbooru/paginator/active_record_extension.rb b/lib/danbooru/paginator/active_record_extension.rb index 79431badb..1cd186eac 100644 --- a/lib/danbooru/paginator/active_record_extension.rb +++ b/lib/danbooru/paginator/active_record_extension.rb @@ -81,7 +81,7 @@ module Danbooru def option_for(key) case key when :limit - limit = @paginator_options.try(:[], :limit) || CurrentUser.user.per_page + limit = @paginator_options.try(:[], :limit) || Danbooru.config.posts_per_page if limit.to_i > 1_000 limit = 1_000 end