volt-repo_cache 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/volt/repo_cache/association.rb +9 -0
- data/lib/volt/repo_cache/collection.rb +10 -4
- data/lib/volt/repo_cache/model.rb +11 -8
- data/lib/volt/repo_cache/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a949a402c250f1b85f04ae00b100102eefe77430
|
4
|
+
data.tar.gz: 077842b65264bfabbe797622dadba64fe8a8fe52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b1f68d6c457986e0b63fbcd3b0ba5fa4a3e43167e8a80f9d2ce33ba64b71f6ac4bf90eb3d7fd7908ca240ce20c66a9a6c88b10f06975b5eca108b6269dd3ddd
|
7
|
+
data.tar.gz: 987d529e193352b8b77d53240f2ce334f32477eb99c28284633e0e8837a240d61ab562de5fe9417647dc9e15dcae410fc947f38f913cdd47da24e11caeb768ac
|
@@ -92,6 +92,15 @@ module Volt
|
|
92
92
|
@local_collection = @foreign_collection = @reciprocal = nil
|
93
93
|
end
|
94
94
|
|
95
|
+
def __debug(level, file, line, method, msg = nil)
|
96
|
+
s = "#{file}[#{line}]:#{self.class.name}##{method}: #{msg}"
|
97
|
+
if RUBY_PLATFORM == 'opal'
|
98
|
+
Volt.logger.debug s
|
99
|
+
else
|
100
|
+
puts s
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
95
104
|
end
|
96
105
|
end
|
97
106
|
end
|
@@ -52,10 +52,14 @@ module Volt
|
|
52
52
|
# models are removed from @marked_from_destruction as
|
53
53
|
# they are flushed, so we need a copy of them to enumerate
|
54
54
|
@marked_for_destruction.values.dup.each do |e|
|
55
|
+
# __debug __method__, __LINE__, "@marked_for_destruction calling #{e.class}:#{e.id}.flush!"
|
55
56
|
promises << e.flush!
|
57
|
+
# __debug __method__, __LINE__, "@marked_for_destruction called #{e.class}:#{e.id}.flush!"
|
56
58
|
end
|
57
59
|
each do |e|
|
60
|
+
# __debug __method__, __LINE__, "each calling #{e.class}:#{e.id}.flush!"
|
58
61
|
promises << e.flush!
|
62
|
+
# __debug __method__, __LINE__, "each called #{e.class}:#{e.id}.flush!"
|
59
63
|
end
|
60
64
|
end
|
61
65
|
Promise.when(*promises)
|
@@ -114,14 +118,16 @@ module Volt
|
|
114
118
|
end
|
115
119
|
@marked_for_destruction[model.id] = model
|
116
120
|
__remove__(model, error_if_absent: true)
|
121
|
+
@cached_ids.delete(model.id)
|
117
122
|
end
|
118
123
|
|
119
124
|
# Called by RepoCache::Model#__destroy__.
|
120
125
|
# Remove model from marked_for_destruction bucket.
|
121
126
|
# Don't worry if we can't find it.
|
122
127
|
def destroyed(model)
|
123
|
-
|
124
|
-
@marked_for_destruction.delete(model.id)
|
128
|
+
# __debug __method__, __LINE__, "#{model.class}.id=#{model.id}"
|
129
|
+
result = @marked_for_destruction.delete(model.id)
|
130
|
+
# __debug __method__, __LINE__, "@marked_for_destruction.delete(#{model.id}) => #{result}"
|
125
131
|
end
|
126
132
|
|
127
133
|
# Collection is being notified (probably by super/self)
|
@@ -197,7 +203,7 @@ module Volt
|
|
197
203
|
raise ArgumentError, "#{model} must be a #{model_class_name}"
|
198
204
|
end
|
199
205
|
if model.cached?
|
200
|
-
__debug __method__, __LINE__, "id=#{model.id} model.cached?=#{model.cached?}"
|
206
|
+
# __debug __method__, __LINE__, "id=#{model.id} model.cached?=#{model.cached?}"
|
201
207
|
raise TypeError, "model.id #{model.id} already in cache"
|
202
208
|
end
|
203
209
|
@cached_ids << model.id
|
@@ -232,7 +238,7 @@ module Volt
|
|
232
238
|
end
|
233
239
|
|
234
240
|
def __debug(method, line, msg = nil)
|
235
|
-
s = "{__FILE__}[#{line}]:#{self.class.name}##{method}: #{msg}"
|
241
|
+
s = "#{__FILE__}[#{line}]:#{self.class.name}##{method}: #{msg}"
|
236
242
|
if RUBY_PLATFORM == 'opal'
|
237
243
|
Volt.logger.debug s
|
238
244
|
else
|
@@ -191,15 +191,16 @@ module Volt
|
|
191
191
|
fail_if_read_only(__method__)
|
192
192
|
if @cache__marked_for_destruction
|
193
193
|
# debug_model __method__, __LINE__, "marked for destruction so call destroy on #{to_h}"
|
194
|
-
|
194
|
+
@cache__marked_for_destruction = false
|
195
|
+
Promise.when(__destroy__, flush_associations)
|
195
196
|
else
|
196
197
|
if dirty?
|
197
|
-
debug_model __method__, __LINE__, "@cache__stored=#{@cache__stored} dirty?=#{dirty?} to_h=#{to_h}"
|
198
|
+
# debug_model __method__, __LINE__, "@cache__stored=#{@cache__stored} dirty?=#{dirty?} to_h=#{to_h}"
|
198
199
|
if stored?
|
199
200
|
# debug_model __method__, __LINE__,"dirty: #{self.class.name}::#{self.id}"
|
200
201
|
__save__
|
201
202
|
else
|
202
|
-
debug_model __method__, __LINE__, "<< to repo: #{self.class.name}::#{self.to_h}"
|
203
|
+
# debug_model __method__, __LINE__, "<< to repo: #{self.class.name}::#{self.to_h}"
|
203
204
|
@cache__stored = true
|
204
205
|
@cache__collection.repo_collection << self
|
205
206
|
# TODO: big problem! once new model saved it should become buffer in cache!
|
@@ -339,23 +340,24 @@ module Volt
|
|
339
340
|
# MESSAGE_BUS is on and there's another connection
|
340
341
|
# (e.g. console) running.
|
341
342
|
# Returns a promise with destroyed model proxy as value.
|
343
|
+
# TODO: destroy any has_many association
|
342
344
|
def model.__destroy__
|
343
345
|
# debug_model __method__, __LINE__
|
344
346
|
fail_if_read_only(__method__)
|
345
|
-
|
347
|
+
debug_model __method__, __LINE__
|
346
348
|
promise = if stored?
|
347
349
|
destroy(caller: self)
|
348
350
|
else
|
349
351
|
Promise.value(self)
|
350
352
|
end
|
351
|
-
|
352
|
-
promise.then do |
|
353
|
-
|
353
|
+
debug_model __method__, __LINE__
|
354
|
+
promise.then do |result|
|
355
|
+
debug_model __method__, __LINE__, "destroy promise result => #{result}"
|
354
356
|
@cache__collection.destroyed(self)
|
355
357
|
uncache
|
356
358
|
self
|
357
359
|
end.fail do |errors|
|
358
|
-
|
360
|
+
debug_model __method__, __LINE__, "destroy failed => #{errors}"
|
359
361
|
errors
|
360
362
|
end
|
361
363
|
end
|
@@ -666,6 +668,7 @@ module Volt
|
|
666
668
|
# debug_model __method__, __LINE__
|
667
669
|
end
|
668
670
|
end
|
671
|
+
@cache__collection.flush!
|
669
672
|
end
|
670
673
|
end
|
671
674
|
model.singleton_class.send(:private, :mark_associations_for_destruction)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: volt-repo_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin Gunn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04
|
11
|
+
date: 2016-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Cache multiple collections or query based subsets from any Volt repository.
|
14
14
|
Provides faster and simpler client-side processing. Reduces the burden of promise
|