Commit 450c0d90 authored by Kerri Miller's avatar Kerri Miller

Extract file_identifiers to avoid looping

parent c3fd0190
...@@ -12,7 +12,6 @@ module Gitlab ...@@ -12,7 +12,6 @@ module Gitlab
@backend = backend @backend = backend
@diff_collection = diff_collection @diff_collection = diff_collection
@redis_key = "highlighted-diff-files:#{diffable.cache_key}" @redis_key = "highlighted-diff-files:#{diffable.cache_key}"
@file_identifiers = @diff_collection.diff_files.collect(&:file_identifier)
end end
# - Reads from cache # - Reads from cache
...@@ -81,6 +80,10 @@ module Gitlab ...@@ -81,6 +80,10 @@ module Gitlab
private private
def file_identifiers
@file_identifiers ||= @diff_collection.diff_files.collect(&:file_identifier)
end
def read_file(diff_file) def read_file(diff_file)
cached_content[diff_file.file_identifier] cached_content[diff_file.file_identifier]
end end
...@@ -93,14 +96,14 @@ module Gitlab ...@@ -93,14 +96,14 @@ module Gitlab
results = [] results = []
Redis::Cache.with do |redis| Redis::Cache.with do |redis|
results = redis.hmget(@redis_key, @file_identifiers) results = redis.hmget(@redis_key, file_identifiers)
end end
results.map! do |result| results.map! do |result|
JSON.parse(result, symbolize_names: true) unless result.nil? JSON.parse(result, symbolize_names: true) unless result.nil?
end end
@file_identifiers.zip(results).to_h file_identifiers.zip(results).to_h
end end
def cacheable?(diff_file) def cacheable?(diff_file)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment