multi_fetch_fragments 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/multi_fetch_fragments.rb +25 -8
- metadata +2 -2
@@ -14,9 +14,10 @@ module MultiFetchFragments
|
|
14
14
|
spacer = find_template(@options[:spacer_template]).render(@view, @locals)
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
results = []
|
18
18
|
|
19
19
|
if ActionController::Base.perform_caching && @options[:cache].present?
|
20
|
+
|
20
21
|
keys_to_collection_map = {}
|
21
22
|
|
22
23
|
@collection.each do |item|
|
@@ -35,31 +36,47 @@ module MultiFetchFragments
|
|
35
36
|
if value.present?
|
36
37
|
collections_object = keys_to_collection_map[key]
|
37
38
|
@collection.delete(collections_object)
|
38
|
-
|
39
|
-
result << value
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
42
|
+
non_cached_results = []
|
43
|
+
|
43
44
|
# sequentially render any non-cached objects remaining, and cache them
|
44
45
|
if @collection.any?
|
45
|
-
|
46
|
+
# debugger
|
47
|
+
|
48
|
+
collection_objects_clone = @collection.clone
|
46
49
|
|
47
50
|
non_cached_results = @template ? collection_with_template : collection_without_template
|
48
51
|
|
49
52
|
non_cached_results.each_with_index do |item, index|
|
50
|
-
|
53
|
+
|
54
|
+
collection_object = collection_objects_clone[index]
|
51
55
|
key = collection_to_keys_map[collection_object]
|
56
|
+
|
57
|
+
debugger if key.blank?
|
58
|
+
|
52
59
|
Rails.cache.write(key, item)
|
53
60
|
end
|
61
|
+
end
|
54
62
|
|
55
|
-
|
63
|
+
# re-sort the result according to the keys that were fed in
|
64
|
+
keys_to_collection_map.each do |key, value|
|
65
|
+
|
66
|
+
# was it in the cache?
|
67
|
+
cached_value = result_hash[key]
|
68
|
+
if cached_value
|
69
|
+
results << result_hash[key]
|
70
|
+
else
|
71
|
+
results << non_cached_results.shift
|
72
|
+
end
|
56
73
|
end
|
57
74
|
|
58
75
|
else
|
59
|
-
|
76
|
+
results = @template ? collection_with_template : collection_without_template
|
60
77
|
end
|
61
78
|
|
62
|
-
|
79
|
+
results.join(spacer).html_safe
|
63
80
|
end
|
64
81
|
|
65
82
|
class Railtie < Rails::Railtie
|
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.6
|
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: 2012-12-
|
12
|
+
date: 2012-12-11 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: nate.kontny@gmail.com
|