Changeset 6396
- Timestamp:
- 03/13/07 02:14:31 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/benchmarking.rb (modified) (1 diff)
- trunk/actionpack/lib/action_controller/filters.rb (modified) (2 diffs)
- trunk/actionpack/lib/action_controller/flash.rb (modified) (2 diffs)
- trunk/actionpack/lib/action_controller/layout.rb (modified) (1 diff)
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/callbacks.rb (modified) (4 diffs)
- trunk/activerecord/lib/active_record/locking/optimistic.rb (modified) (2 diffs)
- trunk/activerecord/lib/active_record/timestamp.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r6350 r6396 1 1 *SVN* 2 3 * Consistent public/protected/private visibility for chained methods. #7813 [dcmanges] 2 4 3 5 * Prefer MIME constants to strings. #7707 [Dan Kubb] trunk/actionpack/lib/action_controller/benchmarking.rb
r6157 r6396 41 41 end 42 42 43 def render_with_benchmark(options = nil, deprecated_status = nil, &block) 44 unless logger 45 render_without_benchmark(options, deprecated_status, &block) 46 else 47 db_runtime = ActiveRecord::Base.connection.reset_runtime if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? 43 protected 44 def render_with_benchmark(options = nil, deprecated_status = nil, &block) 45 unless logger 46 render_without_benchmark(options, deprecated_status, &block) 47 else 48 db_runtime = ActiveRecord::Base.connection.reset_runtime if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? 48 49 49 render_output = nil50 @rendering_runtime = Benchmark::measure{ render_output = render_without_benchmark(options, deprecated_status, &block) }.real50 render_output = nil 51 @rendering_runtime = Benchmark::measure{ render_output = render_without_benchmark(options, deprecated_status, &block) }.real 51 52 52 if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? 53 @db_rt_before_render = db_runtime 54 @db_rt_after_render = ActiveRecord::Base.connection.reset_runtime 55 @rendering_runtime -= @db_rt_after_render 53 if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? 54 @db_rt_before_render = db_runtime 55 @db_rt_after_render = ActiveRecord::Base.connection.reset_runtime 56 @rendering_runtime -= @db_rt_after_render 57 end 58 59 render_output 56 60 end 57 58 render_output 59 end 60 end 61 62 def perform_action_with_benchmark 63 unless logger 64 perform_action_without_benchmark 65 else 66 runtime = [ Benchmark::measure{ perform_action_without_benchmark }.real, 0.0001 ].max 67 68 log_message = "Completed in #{sprintf("%.5f", runtime)} (#{(1 / runtime).floor} reqs/sec)" 69 log_message << rendering_runtime(runtime) if defined?(@rendering_runtime) 70 log_message << active_record_runtime(runtime) if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? 71 log_message << " | #{headers["Status"]}" 72 log_message << " [#{complete_request_uri rescue "unknown"}]" 73 74 logger.info(log_message) 75 response.headers["X-Runtime"] = sprintf("%.5f", runtime) 76 end 77 end 78 61 end 79 62 80 63 private 64 def perform_action_with_benchmark 65 unless logger 66 perform_action_without_benchmark 67 else 68 runtime = [ Benchmark::measure{ perform_action_without_benchmark }.real, 0.0001 ].max 69 70 log_message = "Completed in #{sprintf("%.5f", runtime)} (#{(1 / runtime).floor} reqs/sec)" 71 log_message << rendering_runtime(runtime) if defined?(@rendering_runtime) 72 log_message << active_record_runtime(runtime) if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? 73 log_message << " | #{headers["Status"]}" 74 log_message << " [#{complete_request_uri rescue "unknown"}]" 75 76 logger.info(log_message) 77 response.headers["X-Runtime"] = sprintf("%.5f", runtime) 78 end 79 end 80 81 81 def rendering_runtime(runtime) 82 82 " | Rendering: #{sprintf("%.5f", @rendering_runtime)} (#{sprintf("%d", (@rendering_runtime * 100) / runtime)}%)" trunk/actionpack/lib/action_controller/filters.rb
r5862 r6396 616 616 end 617 617 618 def perform_action_with_filters619 call_filter(self.class.filter_chain, 0)620 end621 622 def process_with_filters(request, response, method = :perform_action, *arguments) #:nodoc:623 @before_filter_chain_aborted = false624 process_without_filters(request, response, method, *arguments)625 end626 627 618 def filter_chain 628 619 self.class.filter_chain … … 655 646 end 656 647 648 protected 649 650 def process_with_filters(request, response, method = :perform_action, *arguments) #:nodoc: 651 @before_filter_chain_aborted = false 652 process_without_filters(request, response, method, *arguments) 653 end 654 657 655 private 656 def perform_action_with_filters 657 call_filter(self.class.filter_chain, 0) 658 end 659 658 660 def process_cleanup_with_filters 659 661 if @before_filter_chain_aborted trunk/actionpack/lib/action_controller/flash.rb
r6178 r6396 137 137 138 138 module InstanceMethods #:nodoc: 139 def assign_shortcuts_with_flash(request, response) #:nodoc: 140 assign_shortcuts_without_flash(request, response) 141 flash(:refresh) 142 end 139 140 protected 141 def reset_session_with_flash 142 reset_session_without_flash 143 remove_instance_variable(:@_flash) 144 flash(:refresh) 145 end 143 146 144 def process_cleanup_with_flash145 flash.sweep if @_session146 process_cleanup_without_flash147 end148 149 def reset_session_with_flash150 reset_session_without_flash151 remove_instance_variable(:@_flash)152 flash(:refresh)153 end154 155 protected156 147 # Access the contents of the flash. Use <tt>flash["notice"]</tt> to read a notice you put there or 157 148 # <tt>flash["notice"] = "hello"</tt> to put a new one. … … 178 169 flash.keep 179 170 end 171 172 private 173 def assign_shortcuts_with_flash(request, response) #:nodoc: 174 assign_shortcuts_without_flash(request, response) 175 flash(:refresh) 176 end 177 178 def process_cleanup_with_flash 179 flash.sweep if @_session 180 process_cleanup_without_flash 181 end 180 182 end 181 183 end trunk/actionpack/lib/action_controller/layout.rb
r6275 r6396 234 234 end 235 235 236 def render_with_a_layout(options = nil, deprecated_status = nil, deprecated_layout = nil, &block) #:nodoc: 237 template_with_options = options.is_a?(Hash) 238 239 if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options, deprecated_layout)) 240 assert_existence_of_template_file(layout) 241 242 options = options.merge :layout => false if template_with_options 243 logger.info("Rendering template within #{layout}") if logger 244 245 if template_with_options 246 content_for_layout = render_with_no_layout(options, &block) 247 deprecated_status = options[:status] || deprecated_status 236 protected 237 def render_with_a_layout(options = nil, deprecated_status = nil, deprecated_layout = nil, &block) #:nodoc: 238 template_with_options = options.is_a?(Hash) 239 240 if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options, deprecated_layout)) 241 assert_existence_of_template_file(layout) 242 243 options = options.merge :layout => false if template_with_options 244 logger.info("Rendering template within #{layout}") if logger 245 246 if template_with_options 247 content_for_layout = render_with_no_layout(options, &block) 248 deprecated_status = options[:status] || deprecated_status 249 else 250 content_for_layout = render_with_no_layout(options, deprecated_status, &block) 251 end 252 253 erase_render_results 254 add_variables_to_assigns 255 @template.instance_variable_set("@content_for_layout", content_for_layout) 256 response.layout = layout 257 render_text(@template.render_file(layout, true), deprecated_status) 248 258 else 249 content_for_layout = render_with_no_layout(options, deprecated_status, &block) 250 end 251 252 erase_render_results 253 add_variables_to_assigns 254 @template.instance_variable_set("@content_for_layout", content_for_layout) 255 response.layout = layout 256 render_text(@template.render_file(layout, true), deprecated_status) 257 else 258 render_with_no_layout(options, deprecated_status, &block) 259 end 260 end 259 render_with_no_layout(options, deprecated_status, &block) 260 end 261 end 261 262 262 263 trunk/activerecord/CHANGELOG
r6388 r6396 1 1 *SVN* 2 3 * Consistent public/protected/private visibility for chained methods. #7813 [dcmanges] 2 4 3 5 * Oracle: fix quoted primary keys and datetime overflow. #7798 [Michael Schoen] trunk/activerecord/lib/active_record/callbacks.rb
r5018 r6396 228 228 result 229 229 end 230 private :initialize_with_callbacks 230 231 231 232 # Is called _before_ Base.save (regardless of whether it's a create or update save). … … 244 245 result 245 246 end 247 private :create_or_update_with_callbacks 246 248 247 249 # Is called _before_ Base.save on new objects that haven't been saved yet (no record exists). … … 256 258 result 257 259 end 260 private :create_with_callbacks 258 261 259 262 # Is called _before_ Base.save on existing objects that have a record. … … 269 272 result 270 273 end 274 private :update_with_callbacks 271 275 272 276 # Is called _before_ Validations.validate (which is part of the Base.save call). trunk/activerecord/lib/active_record/locking/optimistic.rb
r6139 r6396 24 24 module Optimistic 25 25 def self.included(base) #:nodoc: 26 super27 26 base.extend ClassMethods 28 27 … … 42 41 end 43 42 44 def attributes_from_column_definition_with_lock 45 result = attributes_from_column_definition_without_lock 43 private 44 def attributes_from_column_definition_with_lock 45 result = attributes_from_column_definition_without_lock 46 46 47 # If the locking column has no default value set,48 # start the lock version at zero. Note we can't use49 # locking_enabled? at this point as @attributes may50 # not have been initialized yet47 # If the locking column has no default value set, 48 # start the lock version at zero. Note we can't use 49 # locking_enabled? at this point as @attributes may 50 # not have been initialized yet 51 51 52 if lock_optimistically && result.include?(self.class.locking_column)53 result[self.class.locking_column] ||= 054 end52 if lock_optimistically && result.include?(self.class.locking_column) 53 result[self.class.locking_column] ||= 0 54 end 55 55 56 return result 57 end 58 59 def update_with_lock #:nodoc: 60 return update_without_lock unless locking_enabled? 61 62 lock_col = self.class.locking_column 63 previous_value = send(lock_col) 64 send(lock_col + '=', previous_value + 1) 65 66 affected_rows = connection.update(<<-end_sql, "#{self.class.name} Update with optimistic locking") 67 UPDATE #{self.class.table_name} 68 SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false))} 69 WHERE #{self.class.primary_key} = #{quote_value(id)} 70 AND #{self.class.quoted_locking_column} = #{quote_value(previous_value)} 71 end_sql 72 73 unless affected_rows == 1 74 raise ActiveRecord::StaleObjectError, "Attempted to update a stale object" 56 return result 75 57 end 76 58 77 return true 78 end 59 def update_with_lock #:nodoc: 60 return update_without_lock unless locking_enabled? 61 62 lock_col = self.class.locking_column 63 previous_value = send(lock_col) 64 send(lock_col + '=', previous_value + 1) 65 66 affected_rows = connection.update(<<-end_sql, "#{self.class.name} Update with optimistic locking") 67 UPDATE #{self.class.table_name} 68 SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false))} 69 WHERE #{self.class.primary_key} = #{quote_value(id)} 70 AND #{self.class.quoted_locking_column} = #{quote_value(previous_value)} 71 end_sql 72 73 unless affected_rows == 1 74 raise ActiveRecord::StaleObjectError, "Attempted to update a stale object" 75 end 76 77 return true 78 end 79 79 80 80 module ClassMethods trunk/activerecord/lib/active_record/timestamp.rb
r6051 r6396 19 19 module Timestamp 20 20 def self.included(base) #:nodoc: 21 super22 23 21 base.alias_method_chain :create, :timestamps 24 22 base.alias_method_chain :update, :timestamps … … 28 26 end 29 27 30 def create_with_timestamps #:nodoc: 31 if record_timestamps 32 t = self.class.default_timezone == :utc ? Time.now.utc : Time.now 33 write_attribute('created_at', t) if respond_to?(:created_at) && created_at.nil? 34 write_attribute('created_on', t) if respond_to?(:created_on) && created_on.nil? 28 private 29 def create_with_timestamps #:nodoc: 30 if record_timestamps 31 t = self.class.default_timezone == :utc ? Time.now.utc : Time.now 32 write_attribute('created_at', t) if respond_to?(:created_at) && created_at.nil? 33 write_attribute('created_on', t) if respond_to?(:created_on) && created_on.nil? 35 34 36 write_attribute('updated_at', t) if respond_to?(:updated_at) 37 write_attribute('updated_on', t) if respond_to?(:updated_on) 35 write_attribute('updated_at', t) if respond_to?(:updated_at) 36 write_attribute('updated_on', t) if respond_to?(:updated_on) 37 end 38 create_without_timestamps 38 39 end 39 create_without_timestamps40 end41 40 42 def update_with_timestamps #:nodoc: 43 if record_timestamps 44 t = self.class.default_timezone == :utc ? Time.now.utc : Time.now 45 write_attribute('updated_at', t) if respond_to?(:updated_at) 46 write_attribute('updated_on', t) if respond_to?(:updated_on) 41 def update_with_timestamps #:nodoc: 42 if record_timestamps 43 t = self.class.default_timezone == :utc ? Time.now.utc : Time.now 44 write_attribute('updated_at', t) if respond_to?(:updated_at) 45 write_attribute('updated_on', t) if respond_to?(:updated_on) 46 end 47 update_without_timestamps 47 48 end 48 update_without_timestamps49 end50 49 end 51 50 end