Module: Couch::BulkRequest::Post
- Included in:
- Server
- Defined in:
- lib/couch.rb
Instance Method Summary collapse
-
#post_bulk(database, docs) ⇒ Object
Flushes the given hashes to CouchDB.
- #post_bulk_if_big_enough(db, docs) ⇒ Object
- #post_bulk_throttled(db, docs, &block) ⇒ Object
Instance Method Details
#post_bulk(database, docs) ⇒ Object
Flushes the given hashes to CouchDB
221 222 223 224 |
# File 'lib/couch.rb', line 221 def post_bulk(database, docs) body = {:docs => docs}.to_json #.force_encoding('utf-8') post("/#{database}/_bulk_docs", body) end |
#post_bulk_if_big_enough(db, docs) ⇒ Object
241 242 243 244 245 246 247 248 |
# File 'lib/couch.rb', line 241 def post_bulk_if_big_enough(db, docs) flush = (docs.to_json.bytesize / 1024 >= ([:flush_size_mb]*1024) or docs.length >= [:max_array_length]) if flush post_bulk_throttled(db, docs) docs.clear end flush end |
#post_bulk_throttled(db, docs, &block) ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/couch.rb', line 226 def post_bulk_throttled(db, docs, &block) # puts "Flushing #{docs.length} docs" bulk = [] docs.each do |doc| bulk << doc if bulk.to_json.bytesize/1024/1024 > [:flush_size_mb] or bulk.length >= [:max_array_length] handle_bulk_flush(bulk, db, block) end end if bulk.length > 0 handle_bulk_flush(bulk, db, block) end end |