forked from e621ng/e621ng
controller tweaks
This commit is contained in:
parent
096f1be22b
commit
56dd8707fd
@ -2,7 +2,7 @@ class ArtistVersionsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
|
||||
def index
|
||||
@artist_versions = ArtistVersion.search(params[:search]).order("id desc").paginate(params[:page])
|
||||
@artist_versions = ArtistVersion.search(params[:search]).order("id desc").paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@artist_versions)
|
||||
end
|
||||
end
|
||||
|
@ -67,14 +67,14 @@ private
|
||||
end
|
||||
|
||||
def index_by_post
|
||||
@posts = Post.commented_before(Time.now).tag_match(params[:tags]).paginate(params[:page], :limit => 5)
|
||||
@posts = Post.commented_before(Time.now).tag_match(params[:tags]).paginate(params[:page], :limit => 5, :search_count => params[:search])
|
||||
respond_with(@posts) do |format|
|
||||
format.html {render :action => "index_by_post"}
|
||||
end
|
||||
end
|
||||
|
||||
def index_by_comment
|
||||
@comments = Comment.search(params[:search]).order("comments.id DESC").paginate(params[:page])
|
||||
@comments = Comment.search(params[:search]).order("comments.id DESC").paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@comments) do |format|
|
||||
format.html {render :action => "index_by_comment"}
|
||||
end
|
||||
|
@ -17,7 +17,7 @@ class ForumPostsController < ApplicationController
|
||||
|
||||
def index
|
||||
@search = ForumPost.active.search(params[:search])
|
||||
@forum_posts = @search.order("forum_posts.id DESC").paginate(params[:page])
|
||||
@forum_posts = @search.order("forum_posts.id DESC").paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@forum_posts)
|
||||
end
|
||||
|
||||
|
@ -19,7 +19,7 @@ class ForumTopicsController < ApplicationController
|
||||
|
||||
def index
|
||||
@search = ForumTopic.active.search(params[:search])
|
||||
@forum_topics = @search.order("is_sticky DESC, updated_at DESC").paginate(params[:page])
|
||||
@forum_topics = @search.order("is_sticky DESC, updated_at DESC").paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@forum_topics)
|
||||
end
|
||||
|
||||
|
@ -63,8 +63,7 @@ private
|
||||
end
|
||||
|
||||
def index_by_note
|
||||
@search = Note.search(params[:search])
|
||||
@notes = @search.order("id desc").paginate(params[:page])
|
||||
@notes = Note.search(params[:search]).order("id desc").paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@notes) do |format|
|
||||
format.html {render :action => "index_by_note"}
|
||||
end
|
||||
|
@ -1,6 +1,5 @@
|
||||
class PoolVersionsController < ApplicationController
|
||||
def index
|
||||
@search = PoolVersion.search(params[:search])
|
||||
@pool_versions = @search.order("updated_at desc").paginate(params[:page])
|
||||
@pool_versions = PoolVersion.search(params[:search]).order("updated_at desc").paginate(params[:page], :search_count => params[:search])
|
||||
end
|
||||
end
|
||||
|
@ -15,8 +15,7 @@ class PoolsController < ApplicationController
|
||||
end
|
||||
|
||||
def index
|
||||
@search = Pool.active.search(params[:search])
|
||||
@pools = @search.order("updated_at desc").paginate(params[:page])
|
||||
@pools = Pool.active.search(params[:search]).order("updated_at desc").paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@pools)
|
||||
end
|
||||
|
||||
|
@ -2,7 +2,7 @@ class PostVersionsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
|
||||
def index
|
||||
@post_versions = PostVersion.search(params[:search]).order("updated_at desc").paginate(params[:page], :count => (params[:search].present? ? nil : 1_000_000))
|
||||
@post_versions = PostVersion.search(params[:search]).order("updated_at desc").paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@post_versions)
|
||||
end
|
||||
|
||||
|
@ -8,7 +8,7 @@ class TagsController < ApplicationController
|
||||
end
|
||||
|
||||
def index
|
||||
@tags = Tag.search(params[:search]).paginate(params[:page])
|
||||
@tags = Tag.search(params[:search]).paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@tags)
|
||||
end
|
||||
|
||||
|
@ -15,8 +15,7 @@ class UsersController < ApplicationController
|
||||
end
|
||||
|
||||
def index
|
||||
@search = User.search(params[:search])
|
||||
@users = @search.order("users.id desc").paginate(params[:page])
|
||||
@users = User.search(params[:search]).order("users.id desc").paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@users)
|
||||
end
|
||||
|
||||
|
@ -2,8 +2,7 @@ class WikiPageVersionsController < ApplicationController
|
||||
respond_to :json, :html, :xml
|
||||
|
||||
def index
|
||||
@search = WikiPageVersion.search(params[:search])
|
||||
@wiki_page_versions = @search.order("id desc").paginate(params[:page])
|
||||
@wiki_page_versions = WikiPageVersion.search(params[:search]).order("id desc").paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@wiki_page_versions)
|
||||
end
|
||||
|
||||
|
@ -15,8 +15,7 @@ class WikiPagesController < ApplicationController
|
||||
end
|
||||
|
||||
def index
|
||||
@search = WikiPage.search(params[:search])
|
||||
@wiki_pages = @search.order("id desc").paginate(params[:page])
|
||||
@wiki_pages = WikiPage.search(params[:search]).order("id desc").paginate(params[:page], :search_count => params[:search])
|
||||
respond_with(@wiki_pages) do |format|
|
||||
format.html do
|
||||
if @wiki_pages.count == 1
|
||||
|
@ -5,7 +5,7 @@ class NoteVersion < ActiveRecord::Base
|
||||
|
||||
def self.search(params)
|
||||
q = scoped
|
||||
return q if params.blank?
|
||||
params = {} if params.blank?
|
||||
|
||||
if params[:updater_id]
|
||||
q = q.where("updater_id = ?", params[:updater_id].to_i)
|
||||
|
@ -22,7 +22,7 @@ class Pool < ActiveRecord::Base
|
||||
|
||||
def search(params)
|
||||
q = scoped
|
||||
return q if params.blank?
|
||||
params = {} if params.blank?
|
||||
|
||||
if params[:name_matches].present?
|
||||
params[:name_matches] = params[:name_matches].tr(" ", "_")
|
||||
@ -42,10 +42,10 @@ class Pool < ActiveRecord::Base
|
||||
q = q.where("creator_id = ?", params[:creator_id].to_i)
|
||||
end
|
||||
|
||||
if params[:sort] == "updated_at"
|
||||
q = q.order("updated_at desc")
|
||||
else
|
||||
if params[:sort] == "name"
|
||||
q = q.order("name")
|
||||
else
|
||||
q = q.order("updated_at desc")
|
||||
end
|
||||
|
||||
q
|
||||
|
@ -14,7 +14,7 @@ class PostVersion < ActiveRecord::Base
|
||||
|
||||
def search(params)
|
||||
q = scoped
|
||||
return q if params.blank?
|
||||
params = {} if params.blank?
|
||||
|
||||
if params[:updater_name].present?
|
||||
q = q.updater_name(params[:updater_name])
|
||||
|
@ -137,7 +137,7 @@ module Danbooru
|
||||
|
||||
# After this many pages, the paginator will switch to sequential mode.
|
||||
def max_numbered_pages
|
||||
10
|
||||
1_000
|
||||
end
|
||||
|
||||
# Max number of tag subscriptions per user
|
||||
|
@ -69,12 +69,33 @@ module Danbooru
|
||||
end
|
||||
|
||||
def records_per_page
|
||||
(@paginator_options.try(:[], :limit) || Danbooru.config.posts_per_page).to_i
|
||||
option_for(:limit).to_i
|
||||
end
|
||||
|
||||
# When paginating large tables, we want to avoid doing an expensive count query
|
||||
# when the result won't even be used. So when calling paginate you can pass in
|
||||
# an optional :search_count key which points to the search params. If these params
|
||||
# exist, then assume we're doing a search and don't override the default count
|
||||
# behavior. Otherwise, just return some large number so the paginator skips the
|
||||
# count.
|
||||
def option_for(key)
|
||||
case key
|
||||
when :limit
|
||||
@paginator_options.try(:[], :limit) || Danbooru.config.posts_per_page
|
||||
|
||||
when :count
|
||||
if @paginator_options.has_key?(:search_count) && @paginator_options[:search_count].blank?
|
||||
1_000_000
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
# taken from kaminari (https://github.com/amatsuda/kaminari)
|
||||
def total_count
|
||||
return @paginator_options[:count] if @paginator_options[:count]
|
||||
return option_for(:count) if option_for(:count)
|
||||
|
||||
c = except(:offset, :limit, :order)
|
||||
c = c.reorder(nil)
|
||||
|
Loading…
Reference in New Issue
Block a user