Permalink
Browse files

Merge pull request #15 from yoricksijsling/large_collections

Significant speed increase for large collections
  • Loading branch information...
2 parents 8e96ed3 + c4dae9c commit 02783f31a2e2560ac344ff6c27238960de9eaad9 Nathan Kontny committed Mar 24, 2013
Showing with 2 additions and 8 deletions.
  1. +2 −8 lib/multi_fetch_fragments.rb
@@ -21,9 +21,6 @@ def render_collection_with_multi_fetch_cache
additional_cache_options = @options.fetch(:cache_options, {})
keys_to_collection_map = {}
- # clone the original collection so we can manipulate it without affecting the original
- @collection = @collection.clone
-
@collection.each do |item|
key = @options[:cache].respond_to?(:call) ? @options[:cache].call(item) : item
@@ -46,11 +43,8 @@ def render_collection_with_multi_fetch_cache
# if we had a cached value, we don't need to render that object from the collection.
# if it wasn't cached, we need to render those objects as before
- result_hash.each do |key, value|
- if value
- collection_item = keys_to_collection_map[key]
- @collection.delete(collection_item)
- end
+ @collection = (keys_to_collection_map.keys - result_hash.keys).map do |key|
+ keys_to_collection_map[key]
end
non_cached_results = []

0 comments on commit 02783f3

Please sign in to comment.