couch-db 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e3033182fa750ebed0db9996c0b2249377a3188
4
- data.tar.gz: b461244dc466eaeadb3b2de587bbe8844f3f3cc9
3
+ metadata.gz: e92baa55e77c565b84459f4750ab0cd45f0752e5
4
+ data.tar.gz: e951689a319ce402fe6aa741d397e7bf5b00249d
5
5
  SHA512:
6
- metadata.gz: 35912a5df5d840696f2b255a84dde4552c6e61e322f631df75d34e6bb9066b1e5bf19dc75451ac518bade1c047a32479aa83e10a5e229748558bb1bff63224ff
7
- data.tar.gz: d6879f8c757632d04768102b06e3b12f92cfdbe8dbd7cb12931241d6eb761f7b0cafc2e3a15e6f767daab4fe698a6a85d58a457314ecbdd00a7aa11eae8574c9
6
+ metadata.gz: 801b3abbf35221122df1d5b2e22420452a7d77036a7134907f6ac7c625e687902ea4c478aee9421ab9627224efe51db90f8b179aa01381a2c8a5ac8b874720c2
7
+ data.tar.gz: 1775111c62395c8a83ba68b6c9032c650375537a47bbde368376da0e3168dcf6756871ba031ad9bef2dfa7be36ff6b50e8bbb037d0b433624ed811807f172230
@@ -3,4 +3,5 @@ rvm:
3
3
  - 2.1.6
4
4
  - 2.2.2
5
5
  - 2.0.0
6
+ - 1.9.3
6
7
  before_install: gem install bundler -v 1.10
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Maarten Trompper']
10
10
  spec.email = ['maartentrompper@gmail.com']
11
11
 
12
- spec.required_ruby_version = '>= 2'
12
+ spec.required_ruby_version = '>= 1.9'
13
13
 
14
14
  spec.summary = %q{Interface with a CouchDB database. Focuses on bulk requests.}
15
15
  # spec.description = %q{Write a longer description or delete this line.}
@@ -15,7 +15,6 @@ class Hash
15
15
  end
16
16
 
17
17
  module Couch
18
-
19
18
  module BasicRequest
20
19
  def create_postfix(query_params, default='')
21
20
  if query_params
@@ -235,17 +234,13 @@ module Couch
235
234
  post("/#{database}/_bulk_docs", body)
236
235
  end
237
236
 
238
- def post_bulk_throttled(db, docs, max_size_mb: 15, max_array_length: 300, &block)
237
+ def post_bulk_throttled(db, docs, &block)
239
238
  # puts "Flushing #{docs.length} docs"
240
239
  bulk = []
241
- bytesize = 0
242
240
  docs.each do |doc|
243
241
  bulk << doc
244
- # TODO: Note that this may be inexact; see documentation for ObjectSpace.memsize_of
245
- bytesize += ObjectSpace.memsize_of doc
246
- if bytesize/1024/1024 > max_size_mb or bulk.length >= max_array_length
242
+ if bulk.to_json.bytesize/1024/1024 > options[:flush_size_mb] or bulk.length >= options[:max_array_length]
247
243
  handle_bulk_flush(bulk, db, block)
248
- bytesize=0
249
244
  end
250
245
  end
251
246
  if bulk.length > 0
@@ -254,8 +249,8 @@ module Couch
254
249
  end
255
250
 
256
251
 
257
- def post_bulk_if_big_enough(db, docs, flush_size_mb: 10, max_array_length: 300)
258
- flush = (get_bytesize_array(docs) >= (flush_size_mb*1024*1024) or docs.length >= max_array_length)
252
+ def post_bulk_if_big_enough(db, docs)
253
+ flush = (docs.to_json.bytesize / 1024 >= (options[:flush_size_mb]*1024) or docs.length >= options[:max_array_length])
259
254
  if flush
260
255
  post_bulk_throttled(db, docs)
261
256
  docs.clear
@@ -265,25 +260,6 @@ module Couch
265
260
 
266
261
  private
267
262
 
268
- def get_bytesize_array(docs)
269
- bytesize = 0
270
- docs.each do |doc|
271
- # Note that this may be inexact; see documentation for ObjectSpace.memsize_of
272
- bytesize += ObjectSpace.memsize_of doc
273
-
274
- if doc['_attachments']
275
- doc['_attachments'].each do |att|
276
- att.each do |val|
277
- if val['data']
278
- bytesize += val['data'].length # Number of chars, i.e. bytes
279
- end
280
- end
281
- end
282
- end
283
- end
284
- bytesize
285
- end
286
-
287
263
  def handle_bulk_flush(bulk, db, block)
288
264
  res = post_bulk(db, bulk)
289
265
  error_count=0
@@ -306,6 +282,8 @@ module Couch
306
282
  end
307
283
 
308
284
  class Server
285
+ attr_accessor :options
286
+
309
287
  def initialize(url, options)
310
288
  if url.is_a? String
311
289
  url = URI(url)
@@ -313,6 +291,11 @@ module Couch
313
291
  @couch_url = url
314
292
  @options = options
315
293
  @options[:use_ssl] ||= true
294
+ @options[:max_array_length] ||= 250
295
+ @options[:flush_size_mb] ||= 10
296
+ @options[:open_timeout] ||= 5*30
297
+ @options[:read_timeout] ||= 5*30
298
+ @options[:fail_silent] ||= false
316
299
  end
317
300
 
318
301
  def delete(uri, open_timeout: 5*30, read_timeout: 5*30, fail_silent: false)
@@ -1,6 +1,6 @@
1
1
  module Couch
2
2
  # noinspection ALL
3
3
  module DB
4
- VERSION = '0.9.1'
4
+ VERSION = '0.10.0'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couch-db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maarten Trompper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-13 00:00:00.000000000 Z
11
+ date: 2015-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -112,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
112
  requirements:
113
113
  - - ">="
114
114
  - !ruby/object:Gem::Version
115
- version: '2'
115
+ version: '1.9'
116
116
  required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  requirements:
118
118
  - - ">="