YALTools::YaViewDocs is designed to handle huge amount of documents using View API.
To improve performance, the view definition should include the “_count” reduce function or “_sum” function with emit(x, 1).
{ "xxx": { "map": "xxxx", "reduce": "_count" } } or { "xxx": { "map": "... emit(xxx, 1); ...", "reduce": "_sum" } }
Otherwise, the max_numrows method cannot return the correct value. So, the pagination cannot work well.
In this case, please use the YALTools::YaDocs::get_all(options, limit) method instead.
Please refer the unittest script, unittest/ut.yalt.yaview.rb.
view = YALTools::YaViewDocs.new(@couch, @dbname, @designname, @viewname) view.each(opts, @opts[:page], @opts[:unit]) do |rows, skip, page, max_page, max_rows| rows.each do |i| ## rows is an instance of YaJsonRows puts i.to_json end end
# File yalt/yaview.rb, line 443 443: def initialize(couch, dbname, design_name, view_name) 444: @couch = couch 445: @dbname = dbname 446: @debug = @couch.debug if @couch.respond_to?("debug") 447: 448: @design_name = design_name 449: @view_name = view_name 450: 451: @default_query_options = { "reduce" => "false", "descending" => "false", "include_docs" => "true" } 452: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.