Skip to content

Commit

Permalink
converter: improve cache
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed Jun 26, 2014
1 parent 1766234 commit f76c5ee
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions tasks/converter/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ def get_paths_by_type(dir, file_re, tree = get_tree(get_tree_sha(dir)))

def read_files(path, files)
full_path = "https://raw.githubusercontent.com/#@repo/#@branch_sha/#{path}"
if (contents = read_cached_files(path, files))
log_http_get_files files, full_path, true
else
log_http_get_files files, full_path, false
contents = {}
files.map do |name|
Thread.start {
content = open("#{full_path}/#{name}").read
Thread.exclusive { contents[name] = content }
}
end.each(&:join)
write_cached_files path, contents
end
contents = read_cached_files(path, files)
log_http_get_files contents.keys, full_path, true if contents.keys
files -= contents.keys
log_http_get_files files, full_path, false
files.map do |name|
Thread.start {
content = open("#{full_path}/#{name}").read
Thread.exclusive { write_cached_files path, name => content }
}
end.each(&:join)
contents
end

Expand All @@ -29,7 +26,8 @@ def read_cached_files(path, files)
contents = {}
if File.directory?(full_path)
files.each do |name|
contents[name] = File.read("#{full_path}/#{name}", mode: 'rb') || ''
path = "#{full_path}/#{name}"
contents[name] = File.read(path, mode: 'rb') if File.exists?(path)
end
contents
end
Expand Down

0 comments on commit f76c5ee

Please sign in to comment.