Commit 21e4c379 authored by Kerri Miller's avatar Kerri Miller

Key redis hash with file path

parent 450c0d90
......@@ -27,13 +27,13 @@ module Gitlab
def write_if_empty
diff_files = @diff_collection.diff_files
cached_diff_files = read_cache
uncached_files = diff_files.select { |file| cached_diff_files[file.file_identifier].nil? }
uncached_files = diff_files.select { |file| cached_diff_files[file.new_path].nil? }
new_cache_content = {}
uncached_files.each do |diff_file|
next unless cacheable?(diff_file)
new_cache_content[diff_file.file_identifier] = diff_file.highlighted_diff_lines.map(&:to_hash)
new_cache_content[diff_file.new_path] = diff_file.highlighted_diff_lines.map(&:to_hash)
end
write_to_redis_hash(new_cache_content)
......@@ -80,12 +80,12 @@ module Gitlab
private
def file_identifiers
@file_identifiers ||= @diff_collection.diff_files.collect(&:file_identifier)
def file_paths
@file_paths ||= @diff_collection.diffs.collect(&:new_path)
end
def read_file(diff_file)
cached_content[diff_file.file_identifier]
cached_content[diff_file.new_path]
end
def cached_content
......@@ -96,14 +96,14 @@ module Gitlab
results = []
Redis::Cache.with do |redis|
results = redis.hmget(@redis_key, file_identifiers)
results = redis.hmget(@redis_key, file_paths)
end
results.map! do |result|
JSON.parse(result, symbolize_names: true) unless result.nil?
end
file_identifiers.zip(results).to_h
file_paths.zip(results).to_h
end
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