From 2092687bcb35a3d30e1d05d3f5f461d8f4e8f9b7 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 30 Oct 2008 15:25:36 -0500 Subject: Ensure content type gets reset after render_to_string [#1182 state:resolved] --- actionpack/lib/action_controller/base.rb | 1 + actionpack/test/controller/render_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index e9429d3bb2..e73fc32c59 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -933,6 +933,7 @@ module ActionController #:nodoc: def render_to_string(options = nil, &block) #:doc: render(options, &block) ensure + response.content_type = nil erase_render_results reset_variables_added_to_assigns end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index db2d5d885b..da9702a634 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -154,6 +154,10 @@ class TestController < ActionController::Base render :json => {:hello => 'world'}.to_json end + def render_json_with_render_to_string + render :json => {:hello => render_to_string(:partial => 'partial')} + end + def render_custom_code render :text => "hello world", :status => 404 end @@ -772,6 +776,12 @@ class RenderTest < Test::Unit::TestCase assert_equal 'application/json', @response.content_type end + def test_render_json_with_render_to_string + get :render_json_with_render_to_string + assert_equal '{"hello": "partial html"}', @response.body + assert_equal 'application/json', @response.content_type + end + def test_render_custom_code get :render_custom_code assert_response 404 -- cgit v1.2.3 From 0c84b6f9eda20c30b66d8fb99fba637edc1bc37a Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 30 Oct 2008 15:48:03 -0500 Subject: Use database name in query cache thread local key [#1283 state:resolved] --- .../lib/active_record/connection_adapters/abstract/query_cache.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb index 2fc50b9bfa..8543bbf872 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb @@ -34,17 +34,16 @@ module ActiveRecord end def query_cache - Thread.current['query_cache'] + Thread.current["query_cache_for_#{@config[:database]}"] ||= {} end def query_cache=(cache) - Thread.current['query_cache'] = cache + Thread.current["query_cache_for_#{@config[:database]}"] = cache end # Enable the query cache within the block. def cache old, self.query_cache_enabled = query_cache_enabled, true - self.query_cache ||= {} yield ensure clear_query_cache -- cgit v1.2.3 From 2dcdcf1552748f331bf6f6194ffddabd837bcac9 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 30 Oct 2008 15:52:12 -0500 Subject: config.load_paths should be frozen [#728 state:resolved] --- railties/lib/initializer.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 6500b2d309..404f44676e 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -243,6 +243,7 @@ module Rails end # Freeze the arrays so future modifications will fail rather than do nothing mysteriously + configuration.load_paths.freeze configuration.load_once_paths.freeze end -- cgit v1.2.3 From 4df5e1ae8fe3f5f2cf90c91ae4fb6324daf80082 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 30 Oct 2008 16:27:13 -0500 Subject: It is not necessary to store QueryCache in a thread local since the cache is local to the connection object which is managed by the connection pool --- .../connection_adapters/abstract/query_cache.rb | 41 ++++++++-------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb index 8543bbf872..950bd72101 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb @@ -15,7 +15,7 @@ module ActiveRecord method_names.each do |method_name| base.class_eval <<-end_code, __FILE__, __LINE__ def #{method_name}_with_query_dirty(*args) - clear_query_cache if query_cache_enabled + clear_query_cache if @query_cache_enabled #{method_name}_without_query_dirty(*args) end @@ -25,37 +25,24 @@ module ActiveRecord end end - def query_cache_enabled - Thread.current['query_cache_enabled'] - end - - def query_cache_enabled=(flag) - Thread.current['query_cache_enabled'] = flag - end - - def query_cache - Thread.current["query_cache_for_#{@config[:database]}"] ||= {} - end - - def query_cache=(cache) - Thread.current["query_cache_for_#{@config[:database]}"] = cache - end + attr_reader :query_cache, :query_cache_enabled # Enable the query cache within the block. def cache - old, self.query_cache_enabled = query_cache_enabled, true + old, @query_cache_enabled = @query_cache_enabled, true + @query_cache ||= {} yield ensure clear_query_cache - self.query_cache_enabled = old + @query_cache_enabled = old end # Disable the query cache within the block. def uncached - old, self.query_cache_enabled = query_cache_enabled, false + old, @query_cache_enabled = @query_cache_enabled, false yield ensure - self.query_cache_enabled = old + @query_cache_enabled = old end # Clears the query cache. @@ -65,11 +52,11 @@ module ActiveRecord # the same SQL query and repeatedly return the same result each time, silently # undermining the randomness you were expecting. def clear_query_cache - query_cache.clear if query_cache + @query_cache.clear if @query_cache end def select_all_with_query_cache(*args) - if query_cache_enabled + if @query_cache_enabled cache_sql(args.first) { select_all_without_query_cache(*args) } else select_all_without_query_cache(*args) @@ -77,8 +64,8 @@ module ActiveRecord end def columns_with_query_cache(*args) - if query_cache_enabled - query_cache["SHOW FIELDS FROM #{args.first}"] ||= columns_without_query_cache(*args) + if @query_cache_enabled + @query_cache["SHOW FIELDS FROM #{args.first}"] ||= columns_without_query_cache(*args) else columns_without_query_cache(*args) end @@ -87,11 +74,11 @@ module ActiveRecord private def cache_sql(sql) result = - if query_cache.has_key?(sql) + if @query_cache.has_key?(sql) log_info(sql, "CACHE", 0.0) - query_cache[sql] + @query_cache[sql] else - query_cache[sql] = yield + @query_cache[sql] = yield end if Array === result -- cgit v1.2.3 From fc215de52fe1967bb00b5500c3d0dd2ad55880ac Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 30 Oct 2008 16:28:23 -0500 Subject: Revert "config.load_paths should be frozen [#728 state:resolved]" This reverts commit 2dcdcf1552748f331bf6f6194ffddabd837bcac9. --- railties/lib/initializer.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 404f44676e..6500b2d309 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -243,7 +243,6 @@ module Rails end # Freeze the arrays so future modifications will fail rather than do nothing mysteriously - configuration.load_paths.freeze configuration.load_once_paths.freeze end -- cgit v1.2.3