1
0
Fork 0
mirror of https://github.com/twbs/bootstrap-sass.git synced 2022-11-09 12:27:02 -05:00

converter: improve cache

This commit is contained in:
Gleb Mazovetskiy 2014-06-26 18:52:59 +02:00
parent 1766234e9a
commit f76c5ee292

View file

@ -8,19 +8,16 @@ class Converter
def read_files(path, files) def read_files(path, files)
full_path = "https://raw.githubusercontent.com/#@repo/#@branch_sha/#{path}" full_path = "https://raw.githubusercontent.com/#@repo/#@branch_sha/#{path}"
if (contents = read_cached_files(path, files)) contents = read_cached_files(path, files)
log_http_get_files files, full_path, true log_http_get_files contents.keys, full_path, true if contents.keys
else files -= contents.keys
log_http_get_files files, full_path, false log_http_get_files files, full_path, false
contents = {}
files.map do |name| files.map do |name|
Thread.start { Thread.start {
content = open("#{full_path}/#{name}").read content = open("#{full_path}/#{name}").read
Thread.exclusive { contents[name] = content } Thread.exclusive { write_cached_files path, name => content }
} }
end.each(&:join) end.each(&:join)
write_cached_files path, contents
end
contents contents
end end
@ -29,7 +26,8 @@ class Converter
contents = {} contents = {}
if File.directory?(full_path) if File.directory?(full_path)
files.each do |name| 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 end
contents contents
end end