multi_fetch_fragments 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/multi_fetch_fragments.rb +12 -13
- metadata +2 -2
@@ -16,17 +16,14 @@ module MultiFetchFragments
|
|
16
16
|
|
17
17
|
results = []
|
18
18
|
|
19
|
-
if
|
19
|
+
if cache_collection?
|
20
20
|
|
21
21
|
additional_cache_options = @options.fetch(:cache_options, {})
|
22
22
|
keys_to_collection_map = {}
|
23
23
|
|
24
|
-
# clone the original collection so we can manipulate it without affecting the original
|
25
|
-
@collection = @collection.clone
|
26
|
-
|
27
24
|
@collection.each do |item|
|
28
|
-
key = @options[:cache].
|
29
|
-
|
25
|
+
key = @options[:cache].respond_to?(:call) ? @options[:cache].call(item) : item
|
26
|
+
|
30
27
|
key_with_optional_digest = nil
|
31
28
|
if defined?(@view.fragment_name_with_digest)
|
32
29
|
key_with_optional_digest = @view.fragment_name_with_digest(key)
|
@@ -34,7 +31,7 @@ module MultiFetchFragments
|
|
34
31
|
key_with_optional_digest = key
|
35
32
|
end
|
36
33
|
|
37
|
-
expanded_key = @view.controller.fragment_cache_key(key_with_optional_digest)
|
34
|
+
expanded_key = @view.controller.fragment_cache_key(key_with_optional_digest)
|
38
35
|
|
39
36
|
keys_to_collection_map[expanded_key] = item
|
40
37
|
end
|
@@ -44,13 +41,10 @@ module MultiFetchFragments
|
|
44
41
|
|
45
42
|
result_hash = Rails.cache.read_multi(mutable_keys)
|
46
43
|
|
47
|
-
# if we had a cached value, we don't need to render that object from the collection.
|
44
|
+
# if we had a cached value, we don't need to render that object from the collection.
|
48
45
|
# if it wasn't cached, we need to render those objects as before
|
49
|
-
result_hash.
|
50
|
-
|
51
|
-
collection_item = keys_to_collection_map[key]
|
52
|
-
@collection.delete(collection_item)
|
53
|
-
end
|
46
|
+
@collection = (keys_to_collection_map.keys - result_hash.keys).map do |key|
|
47
|
+
keys_to_collection_map[key]
|
54
48
|
end
|
55
49
|
|
56
50
|
non_cached_results = []
|
@@ -81,6 +75,11 @@ module MultiFetchFragments
|
|
81
75
|
results.join(spacer).html_safe
|
82
76
|
end
|
83
77
|
|
78
|
+
def cache_collection?
|
79
|
+
cache_option = @options[:cache].presence || @locals[:cache].presence
|
80
|
+
ActionController::Base.perform_caching && cache_option
|
81
|
+
end
|
82
|
+
|
84
83
|
class Railtie < Rails::Railtie
|
85
84
|
initializer "multi_fetch_fragments.initialize" do |app|
|
86
85
|
ActionView::PartialRenderer.class_eval do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_fetch_fragments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec-rails
|