couchbase-orm 0.0.10 → 0.0.11

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: 337cd9767138dc33f0f8c5e37efeaa702939549b
4
- data.tar.gz: ecbff763de775b31be872e00bc4d92e1f8d72a88
3
+ metadata.gz: 6fd4a43082ca5d80291db012e1434dc09830a8e5
4
+ data.tar.gz: ae0fd140002527cd633658d5ad52479d9f4a2a6a
5
5
  SHA512:
6
- metadata.gz: 89cfe54e91222fec853e1d17749d01b8410afd1d595a3b4180f9ea769f9b2b238fc7b6f69ae4e1c5e79b19d4cbeb1c82c0da63122b47033660a65321615bae51
7
- data.tar.gz: 016a9c19ffe4f39f5f9cf856a26138081f17e1216878136c735c2d346278c695dfa05d8150ca49c593b0e7778ad7b6c1c628bf2fea7024f4525a4c946c48d85c
6
+ metadata.gz: 9e75b6386a260d835ee1af1a193fe2445fe81761def69396321314b666fb5d10db0239869563f9fa6accc7c8cf3315f88e5a2bb5a1093b930473d77204b9ecd9
7
+ data.tar.gz: 9bbaa54b9b611e1268a78bef595e96e355c8e0880c4bc9da4e69c5e86c8c23a9fe3a0a07e5efa69790225b4bd493f67ff6c28da37b17251c1a2587f11102a1b2
data/lib/couchbase-orm.rb CHANGED
@@ -9,7 +9,11 @@ module CouchbaseOrm
9
9
  autoload :Base, 'couchbase-orm/base'
10
10
 
11
11
  def self.try_load(id)
12
- result = id.respond_to?(:cas) ? id : CouchbaseOrm::Base.bucket.get(id, quiet: true, extended: true)
12
+ result = nil
13
+ ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
14
+ result = id.respond_to?(:cas) ? id : CouchbaseOrm::Base.bucket.get(id, quiet: true, extended: true)
15
+ end
16
+
13
17
  if result && result.value.is_a?(Hash) && result.value[:type]
14
18
  ddoc = result.value[:type]
15
19
  ::CouchbaseOrm::Base.descendants.each do |model|
@@ -102,7 +102,10 @@ module CouchbaseOrm
102
102
  raise Libcouchbase::Error::EmptyKey, 'no id(s) provided'
103
103
  end
104
104
 
105
- records = bucket.get(*ids, **options)
105
+ records = nil
106
+ ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
107
+ records = bucket.get(*ids, **options)
108
+ end
106
109
 
107
110
  records = records.is_a?(Array) ? records : [records]
108
111
  records.map! { |record|
@@ -123,7 +126,11 @@ module CouchbaseOrm
123
126
  alias_method :[], :find_by_id
124
127
 
125
128
  def exists?(id)
126
- !bucket.get(id, quiet: true).nil?
129
+ val = false
130
+ ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
131
+ val = bucket.get(id, quiet: true).nil?
132
+ end
133
+ !val
127
134
  end
128
135
  alias_method :has_key?, :exists?
129
136
  end
@@ -99,7 +99,9 @@ module CouchbaseOrm
99
99
  # The record is simply removed, no callbacks are executed.
100
100
  def delete(with_cas: false, **options)
101
101
  options[:cas] = @__metadata__.cas if with_cas
102
- self.class.bucket.delete(@__metadata__.key, options)
102
+ ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
103
+ self.class.bucket.delete(@__metadata__.key, options)
104
+ end
103
105
 
104
106
  @__metadata__.key = nil
105
107
  @id = nil
@@ -121,7 +123,9 @@ module CouchbaseOrm
121
123
  destroy_associations!
122
124
 
123
125
  options[:cas] = @__metadata__.cas if with_cas
124
- self.class.bucket.delete(@__metadata__.key, options)
126
+ ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
127
+ self.class.bucket.delete(@__metadata__.key, options)
128
+ end
125
129
 
126
130
  @__metadata__.key = nil
127
131
  @id = nil
@@ -165,7 +169,10 @@ module CouchbaseOrm
165
169
  key = @__metadata__.key
166
170
  raise "unable to reload, model not persisted" unless key
167
171
 
168
- resp = self.class.bucket.get(key, quiet: false, extended: true)
172
+ resp = nil
173
+ ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
174
+ resp = self.class.bucket.get(key, quiet: false, extended: true)
175
+ end
169
176
  @__attributes__ = ::ActiveSupport::HashWithIndifferentAccess.new(resp.value)
170
177
  @__metadata__.key = resp.key
171
178
  @__metadata__.cas = resp.cas
@@ -177,7 +184,10 @@ module CouchbaseOrm
177
184
 
178
185
  # Updates the TTL of the document
179
186
  def touch(**options)
180
- res = self.class.bucket.touch(@__metadata__.key, async: false, **options)
187
+ res = nil
188
+ ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
189
+ res = self.class.bucket.touch(@__metadata__.key, async: false, **options)
190
+ end
181
191
  @__metadata__.cas = resp.cas
182
192
  self
183
193
  end
@@ -198,7 +208,11 @@ module CouchbaseOrm
198
208
 
199
209
  _id = @__metadata__.key
200
210
  options[:cas] = @__metadata__.cas if with_cas
201
- resp = self.class.bucket.replace(_id, @__attributes__, **options)
211
+
212
+ resp = nil
213
+ ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
214
+ resp = self.class.bucket.replace(_id, @__attributes__, **options)
215
+ end
202
216
 
203
217
  # Ensure the model is up to date
204
218
  @__metadata__.key = resp.key
@@ -220,7 +234,10 @@ module CouchbaseOrm
220
234
  @__attributes__.delete(:id)
221
235
 
222
236
  _id = @id || self.class.uuid_generator.next(self)
223
- resp = self.class.bucket.add(_id, @__attributes__, **options)
237
+ resp = nil
238
+ ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
239
+ resp = self.class.bucket.add(_id, @__attributes__, **options)
240
+ end
224
241
 
225
242
  # Ensure the model is up to date
226
243
  @__metadata__.key = resp.key
@@ -50,13 +50,18 @@ module CouchbaseOrm
50
50
  # use the bucket key as an index - lookup records by attr values
51
51
  define_singleton_method(find_by_method) do |*values|
52
52
  key = self.send(class_bucket_key_method, *values)
53
- id = self.bucket.get(key, quiet: true)
53
+ id = nil
54
+ ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
55
+ id = self.bucket.get(key, quiet: true)
56
+ end
54
57
  if id
55
58
  mod = self.find_by_id(id)
56
59
  return mod if mod
57
60
 
58
61
  # Clean up record if the id doesn't exist
59
- self.bucket.delete(key, quiet: true)
62
+ ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
63
+ self.bucket.delete(key, quiet: true)
64
+ end
60
65
  end
61
66
 
62
67
  nil
@@ -98,10 +103,14 @@ module CouchbaseOrm
98
103
  # new one. the id of the current record is used as the key's value.
99
104
  after_save do |record|
100
105
  original_key = instance_variable_get(original_bucket_key_var)
101
- record.class.bucket.delete(original_key, quiet: true) if original_key
106
+ ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
107
+ record.class.bucket.delete(original_key, quiet: true) if original_key
108
+ end
102
109
 
103
110
  unless presence == false && attrs.length == 1 && record[attrs[0]].nil?
104
- record.class.bucket.set(record.send(bucket_key_method), record.id, plain: true)
111
+ ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
112
+ record.class.bucket.set(record.send(bucket_key_method), record.id, plain: true)
113
+ end
105
114
  end
106
115
  instance_variable_set(original_bucket_key_var, nil)
107
116
  end
@@ -109,7 +118,9 @@ module CouchbaseOrm
109
118
  # cleanup by removing the bucket key before the record is deleted
110
119
  # TODO: handle unpersisted, modified component values
111
120
  before_destroy do |record|
112
- record.class.bucket.delete(record.send(bucket_key_method), quiet: true)
121
+ ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
122
+ record.class.bucket.delete(record.send(bucket_key_method), quiet: true)
123
+ end
113
124
  true
114
125
  end
115
126
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true, encoding: ASCII-8BIT
2
2
 
3
3
  module CouchbaseOrm
4
- VERSION = '0.0.10'
4
+ VERSION = '0.0.11'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchbase-orm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen von Takach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-23 00:00:00.000000000 Z
11
+ date: 2016-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libcouchbase