Fixed a bug in the pagination code that caused it to paginate over records outside of the scope of the view parameters.

This commit is contained in:
John Wood 2009-08-19 12:26:25 -05:00 committed by Matt Aimonetti
parent 2057e59777
commit b0dca70b02
2 changed files with 20 additions and 4 deletions

View file

@ -204,8 +204,9 @@ module CouchRest
def pagination_options(page, per_page)
view_options = @view_options.clone
if @last_key && @last_docid && @last_page == page - 1
view_options.delete(:key)
options = { :startkey => @last_key, :startkey_docid => @last_docid, :limit => per_page, :skip => 1 }
key = view_options.delete(:key)
end_key = view_options[:endkey] || key
options = { :startkey => @last_key, :endkey => end_key, :startkey_docid => @last_docid, :limit => per_page, :skip => 1 }
else
options = { :limit => per_page, :skip => per_page * (page - 1) }
end