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 +4 -4
- data/.travis.yml +1 -0
- data/couch-request.gemspec +1 -1
- data/lib/couch.rb +11 -28
- data/lib/couch/db/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e92baa55e77c565b84459f4750ab0cd45f0752e5
|
4
|
+
data.tar.gz: e951689a319ce402fe6aa741d397e7bf5b00249d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 801b3abbf35221122df1d5b2e22420452a7d77036a7134907f6ac7c625e687902ea4c478aee9421ab9627224efe51db90f8b179aa01381a2c8a5ac8b874720c2
|
7
|
+
data.tar.gz: 1775111c62395c8a83ba68b6c9032c650375537a47bbde368376da0e3168dcf6756871ba031ad9bef2dfa7be36ff6b50e8bbb037d0b433624ed811807f172230
|
data/.travis.yml
CHANGED
data/couch-request.gemspec
CHANGED
@@ -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 = '>=
|
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.}
|
data/lib/couch.rb
CHANGED
@@ -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,
|
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
|
-
|
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
|
258
|
-
flush = (
|
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)
|
data/lib/couch/db/version.rb
CHANGED
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.
|
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-
|
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: '
|
115
|
+
version: '1.9'
|
116
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
117
|
requirements:
|
118
118
|
- - ">="
|