Permalink
Browse files

Improve performance when fetching the first document of a view

  • Loading branch information...
1 parent aa743e7 commit 65086ea40260d6ff5c9177532f25f93c4c49cdb0 @matthiasjakel matthiasjakel committed Apr 18, 2012
Showing with 4 additions and 2 deletions.
  1. +1 −0 lib/couch_potato/database.rb
  2. +3 −2 lib/couch_potato/view/base_view_spec.rb
@@ -64,6 +64,7 @@ def view(spec)
# returns the first result from a #view query or nil
def first(spec)
+ spec.view_parameters = spec.view_parameters.merge({:limit => 1})
view(spec).first
end
@@ -1,8 +1,9 @@
module CouchPotato
module View
class BaseViewSpec
- attr_reader :reduce_function, :list_name, :list_function, :design_document, :view_name,
- :view_parameters, :klass, :options, :language
+ attr_reader :reduce_function, :list_name, :list_function, :design_document, :view_name, :klass, :options, :language
+ attr_accessor :view_parameters
+
private :klass, :options
def initialize(klass, view_name, options, view_parameters)

0 comments on commit 65086ea

Please sign in to comment.