Skip to content

Commit

Permalink
Restore stale session check and move after dispatch development clean…
Browse files Browse the repository at this point in the history
…ups before the request
  • Loading branch information
josh committed Feb 6, 2009
1 parent 96d6105 commit 7259baa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
7 changes: 2 additions & 5 deletions actionpack/lib/action_controller/dispatcher.rb
Expand Up @@ -7,7 +7,6 @@ def define_dispatcher_callbacks(cache_classes)
unless cache_classes
# Development mode callbacks
before_dispatch :reload_application
after_dispatch :cleanup_application

ActionView::Helpers::AssetTagHelper.cache_asset_timestamps = false
end
Expand Down Expand Up @@ -93,11 +92,9 @@ def reload_application
run_callbacks :prepare_dispatch

Routing::Routes.reload
end

# Cleanup the application by clearing out loaded classes so they can
# be reloaded on the next request without restarting the server.
def cleanup_application
# Cleanup the application by clearing out loaded classes so they can
# be reloaded on the next request without restarting the server.
ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)
ActiveSupport::Dependencies.clear
ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord)
Expand Down
25 changes: 22 additions & 3 deletions actionpack/lib/action_controller/session/abstract_store.rb
Expand Up @@ -58,9 +58,28 @@ def loaded?
end

def load!
@id, session = @by.send(:load_session, @env)
replace(session)
@loaded = true
stale_session_check! do
@id, session = @by.send(:load_session, @env)
replace(session)
@loaded = true
end
end

def stale_session_check!
yield
rescue ArgumentError => argument_error
if argument_error.message =~ %r{undefined class/module ([\w:]*\w)}
begin
# Note that the regexp does not allow $1 to end with a ':'
$1.constantize
rescue LoadError, NameError => const_error
raise ActionController::SessionRestoreError, "Session contains objects whose class definition isn\\'t available.\nRemember to require the classes for all objects kept in the session.\n(Original exception: \#{const_error.message} [\#{const_error.class}])\n"

This comment has been minimized.

Copy link
@nertzy

nertzy May 18, 2010

Contributor

This line is over-escaped.

end

retry
else
raise
end
end
end

Expand Down

2 comments on commit 7259baa

@pixeltrix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has huge effect if you’re using the Thinking Sphinx plugin. TS loads all the models using a to_prepare callback which is then dumped by the call to ActiveSupport::Dependencies.clear. What was the reason for moving cleanup_application into reload_application? Maybe we could move the cleanup stuff before the call to run_callbacks?

@pixeltrix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lighthouse ticket created:
http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1898-clearing-dependencies-in-reload_application-performance-issue

Please sign in to comment.