Skip to content
This repository
Browse code

Move the file exists checks outside write_asset_file_contents.

This lets us avoid the relatively costly trip through compute_*_paths if the file already exists.
  • Loading branch information...
commit d79cde37ea9a14fc6625297f40050296af7f7630 1 parent 12cf8f3
Michael Koziarski NZKoz authored

Showing 1 changed file with 4 additions and 6 deletions. Show diff stats Hide diff stats

  1. +4 6 actionpack/lib/action_view/helpers/asset_tag_helper.rb
10 actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -243,7 +243,7 @@ def javascript_include_tag(*sources)
243 243 joined_javascript_name = (cache == true ? "all" : cache) + ".js"
244 244 joined_javascript_path = File.join(JAVASCRIPTS_DIR, joined_javascript_name)
245 245
246   - write_asset_file_contents(joined_javascript_path, compute_javascript_paths(sources))
  246 + write_asset_file_contents(joined_javascript_path, compute_javascript_paths(sources)) unless File.exists?(joined_javascript_path)
247 247 javascript_src_tag(joined_javascript_name, options)
248 248 else
249 249 expand_javascript_sources(sources).collect { |source| javascript_src_tag(source, options) }.join("\n")
@@ -370,7 +370,7 @@ def stylesheet_link_tag(*sources)
370 370 joined_stylesheet_name = (cache == true ? "all" : cache) + ".css"
371 371 joined_stylesheet_path = File.join(STYLESHEETS_DIR, joined_stylesheet_name)
372 372
373   - write_asset_file_contents(joined_stylesheet_path, compute_stylesheet_paths(sources))
  373 + write_asset_file_contents(joined_stylesheet_path, compute_stylesheet_paths(sources)) unless File.exists?(joined_stylesheet_path)
374 374 stylesheet_tag(joined_stylesheet_name, options)
375 375 else
376 376 expand_stylesheet_sources(sources).collect { |source| stylesheet_tag(source, options) }.join("\n")
@@ -601,10 +601,8 @@ def join_asset_file_contents(paths)
601 601 end
602 602
603 603 def write_asset_file_contents(joined_asset_path, asset_paths)
604   - unless file_exist?(joined_asset_path)
605   - FileUtils.mkdir_p(File.dirname(joined_asset_path))
606   - File.open(joined_asset_path, "w+") { |cache| cache.write(join_asset_file_contents(asset_paths)) }
607   - end
  604 + FileUtils.mkdir_p(File.dirname(joined_asset_path))
  605 + File.open(joined_asset_path, "w+") { |cache| cache.write(join_asset_file_contents(asset_paths)) }
608 606 end
609 607 end
610 608 end

0 comments on commit d79cde3

Please sign in to comment.
Something went wrong with that request. Please try again.