Permalink
Browse files

Prevent a request to CouchDB from being issued for an empty doc id ar…

…ray.
  • Loading branch information...
1 parent 98ec24e commit dfe00c13a412d7f80664951a574811707e145274 @paulcarey committed Apr 15, 2010
Showing with 7 additions and 4 deletions.
  1. +2 −0 lib/relaxdb/relaxdb.rb
  2. +5 −4 spec/migration_spec.rb
View
@@ -122,6 +122,8 @@ def load(ids, atts={})
# RelaxDB.logger.debug(caller.inject("#{db.name}/#{ids}\n") { |a, i| a += "#{i}\n" })
if ids.is_a? Array
+ return [] if ids.empty?
+
resp = db.post("_all_docs?include_docs=true", {:keys => ids}.to_json)
data = JSON.parse(resp.body)
data["rows"].map { |row| row["doc"] ? create_obj_from_doc(row["doc"]) : nil }
View
@@ -42,17 +42,18 @@
RelaxDB.db.reset_req_count
end
- # Note: three requests per migration loop, plus two for the final loop
- # where no migration actually occurs
+ # Note: three requests per migration loop, plus one for the final loop
+ # where no migration actually occurs. (It would be two for the final
+ # loop except a request isn't isn't the id array passed to load is empty)
it "should operate on a doc set of the given size aka limit" do
@mig.run(Primitives, 1) { |p| p.num *= p.num; p }
- RelaxDB.db.req_count.should == 5 * 3 + 2
+ RelaxDB.db.req_count.should == 5 * 3 + 1
Primitives.by_num.map { |p| p.num }.should == [1, 4, 9, 16, 25]
end
it "should operate on a doc set of default size" do
@mig.run(Primitives) { |p| p.num *= p.num; p }
- RelaxDB.db.req_count.should == 1 * 3 + 2
+ RelaxDB.db.req_count.should == 1 * 3 + 1
Primitives.by_num.map { |p| p.num }.should == [1, 4, 9, 16, 25]
end

0 comments on commit dfe00c1

Please sign in to comment.