Permalink
Browse files

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...
1 parent 12cf8f3 commit d79cde37ea9a14fc6625297f40050296af7f7630 @NZKoz NZKoz committed Jul 1, 2008
Showing with 4 additions and 6 deletions.
  1. +4 −6 actionpack/lib/action_view/helpers/asset_tag_helper.rb
View
10 actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -243,7 +243,7 @@ def javascript_include_tag(*sources)
joined_javascript_name = (cache == true ? "all" : cache) + ".js"
joined_javascript_path = File.join(JAVASCRIPTS_DIR, joined_javascript_name)
- write_asset_file_contents(joined_javascript_path, compute_javascript_paths(sources))
+ write_asset_file_contents(joined_javascript_path, compute_javascript_paths(sources)) unless File.exists?(joined_javascript_path)
javascript_src_tag(joined_javascript_name, options)
else
expand_javascript_sources(sources).collect { |source| javascript_src_tag(source, options) }.join("\n")
@@ -370,7 +370,7 @@ def stylesheet_link_tag(*sources)
joined_stylesheet_name = (cache == true ? "all" : cache) + ".css"
joined_stylesheet_path = File.join(STYLESHEETS_DIR, joined_stylesheet_name)
- write_asset_file_contents(joined_stylesheet_path, compute_stylesheet_paths(sources))
+ write_asset_file_contents(joined_stylesheet_path, compute_stylesheet_paths(sources)) unless File.exists?(joined_stylesheet_path)
stylesheet_tag(joined_stylesheet_name, options)
else
expand_stylesheet_sources(sources).collect { |source| stylesheet_tag(source, options) }.join("\n")
@@ -601,10 +601,8 @@ def join_asset_file_contents(paths)
end
def write_asset_file_contents(joined_asset_path, asset_paths)
- unless file_exist?(joined_asset_path)
- FileUtils.mkdir_p(File.dirname(joined_asset_path))
- File.open(joined_asset_path, "w+") { |cache| cache.write(join_asset_file_contents(asset_paths)) }
- end
+ FileUtils.mkdir_p(File.dirname(joined_asset_path))
+ File.open(joined_asset_path, "w+") { |cache| cache.write(join_asset_file_contents(asset_paths)) }
end
end
end

0 comments on commit d79cde3

Please sign in to comment.