jchris-couchrest 0.12.4 → 0.12.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/couchrest/core/database.rb +8 -6
- data/lib/couchrest.rb +1 -1
- metadata +1 -1
@@ -149,16 +149,18 @@ module CouchRest
|
|
149
149
|
# missing ids, supply one from the uuid cache.
|
150
150
|
#
|
151
151
|
# If called with no arguments, bulk saves the cache of documents to be bulk saved.
|
152
|
-
def bulk_save
|
152
|
+
def bulk_save(docs = nil, use_uuids = true)
|
153
153
|
if docs.nil?
|
154
154
|
docs = @bulk_save_cache
|
155
155
|
@bulk_save_cache = []
|
156
156
|
end
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
157
|
+
if (use_uuids)
|
158
|
+
ids, noids = docs.partition{|d|d['_id']}
|
159
|
+
uuid_count = [noids.length, @server.uuid_batch_count].max
|
160
|
+
noids.each do |doc|
|
161
|
+
nextid = @server.next_uuid(uuid_count) rescue nil
|
162
|
+
doc['_id'] = nextid if nextid
|
163
|
+
end
|
162
164
|
end
|
163
165
|
CouchRest.post "#{@root}/_bulk_docs", {:docs => docs}
|
164
166
|
end
|
data/lib/couchrest.rb
CHANGED