From 8db51ee3c0d3e2f339da5537177b38129c5d21fa Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 24 Sep 2007 08:26:04 +0000 Subject: Cache more file existence checks. Flip-flop escaping. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7610 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/action_view/helpers/asset_tag_helper.rb | 25 ++++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 060fb5a2ce..4306e48343 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -179,7 +179,7 @@ module ActionView joined_javascript_name = (cache == true ? "all" : cache) + ".js" joined_javascript_path = File.join(JAVASCRIPTS_DIR, joined_javascript_name) - if !File.exists?(joined_javascript_path) + if !file_exist?(joined_javascript_path) File.open(joined_javascript_path, "w+") do |cache| javascript_paths = expand_javascript_sources(sources).collect do |source| compute_public_path(source, 'javascripts', 'js', false) @@ -288,8 +288,7 @@ module ActionView joined_stylesheet_name = (cache == true ? "all" : cache) + ".css" joined_stylesheet_path = File.join(STYLESHEETS_DIR, joined_stylesheet_name) - @@file_exist_cache ||= {} - if !(@@file_exist_cache[joined_stylesheet_name] ||= File.exist?(joined_stylesheet_path)) + if !file_exist?(joined_stylesheet_path) File.open(joined_stylesheet_path, "w+") do |cache| stylesheet_paths = expand_stylesheet_sources(sources).collect do |source| compute_public_path(source, 'stylesheets', 'css', false) @@ -297,21 +296,19 @@ module ActionView cache.write(join_asset_file_contents(stylesheet_paths)) end - - @@file_exist_cache[joined_stylesheet_name] = true end tag("link", { "rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen", "href" => html_escape(stylesheet_path(joined_stylesheet_name)) - }.merge(options), false, true) + }.merge(options), false, false) else options.delete("cache") expand_stylesheet_sources(sources).collect do |source| tag("link", { "rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen", "href" => html_escape(stylesheet_path(source)) - }.merge(options), false, true) + }.merge(options), false, false) end.join("\n") end end @@ -371,6 +368,16 @@ module ActionView end private + def file_exist?(path) + @@file_exist_cache ||= {} + if !(@@file_exist_cache[path] ||= File.exist?(path)) + @@file_exist_cache[path] = true + false + else + true + end + end + # Add the .ext if not present. Return full URLs otherwise untouched. # Prefix with /dir/ if lacking a leading /. Account for relative URL # roots. Rewrite the asset path for cache-busting asset ids. Include @@ -416,7 +423,7 @@ module ActionView asset_id else @@asset_id_cache[source] ||= - if File.exist?(path = File.join(ASSETS_DIR, source)) + if file_exist?(path = File.join(ASSETS_DIR, source)) File.mtime(path).to_i.to_s else '' @@ -444,7 +451,7 @@ module ActionView sources[(sources.index(:defaults) + 1)..sources.length] sources.delete(:defaults) - sources << "application" if File.exists?(File.join(JAVASCRIPTS_DIR, "application.js")) + sources << "application" if file_exist?(File.join(JAVASCRIPTS_DIR, "application.js")) end sources -- cgit v1.2.3