Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Hack to improve performance with mongoid 2.4

There was a problem with mongo driver used in mongoid 2.4. I
incorporated something like pagination in search, to limit number of
documents queried.
  • Loading branch information...
commit 0888e88611987a101a04cb0363c221710ac9ddd3 1 parent 59a2f48
@Ostrzy Ostrzy authored
View
5 lib/active_admin/mongoid/adaptor.rb
@@ -4,11 +4,12 @@ module Adaptor
class Search
attr_reader :base, :query, :query_hash, :search_params
- def initialize(object, search_params = {})
+ def initialize(object, search_params = {}, per_page = 30, page = 1)
@base = object
@search_params = search_params
@query_hash = get_query_hash(search_params)
- @query = @base.where(@query_hash)
+ vpage = page.to_i > 0 ? page.to_i : 1
+ @query = @base.where(@query_hash).limit(per_page).skip(per_page * (vpage - 1))
end
def respond_to?(method_id)
View
7 lib/active_admin/mongoid/resource.rb
@@ -6,6 +6,10 @@ class ActiveAdmin::Resource
def resource_table_name
resource_class.collection_name
end
+
+ def mongoid_per_page
+ per_page
+ end
end
ActiveAdmin::ResourceController # autoload
@@ -22,7 +26,6 @@ def sort_order(chain)
end
def search(chain)
- @search = ActiveAdmin::Mongoid::Adaptor::Search.new(chain, clean_search_params(params[:q]))
+ @search = ActiveAdmin::Mongoid::Adaptor::Search.new(chain, clean_search_params(params[:q]), active_admin_config.mongoid_per_page, params[:page])
end
-
end
Please sign in to comment.
Something went wrong with that request. Please try again.