Skip to content

Commit

Permalink
load external libraries only once, fixes #1662
Browse files Browse the repository at this point in the history
  • Loading branch information
ujifgc committed May 7, 2014
1 parent b441c57 commit 8e23d81
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
15 changes: 15 additions & 0 deletions padrino-core/lib/padrino-core/reloader.rb
Expand Up @@ -87,6 +87,7 @@ def safe_load(file, options={})
began_at = Time.now
file = figure_path(file)
return unless options[:force] || file_changed?(file)
return require(file) if external_feature?(file)

Storage.prepare(file) # might call #safe_load recursively
logger.devel(file_new?(file) ? :loading : :reload, began_at, file)
Expand Down Expand Up @@ -116,6 +117,13 @@ def remove_constant(const)
rescue NameError
end

##
# Remove a feature from $LOADED_FEATURES so it can be required again.
#
def remove_feature(file)
$LOADED_FEATURES.delete(file) unless external_feature?(file)
end

##
# Returns the list of special tracked files for Reloader.
#
Expand Down Expand Up @@ -229,6 +237,13 @@ def files_for_rotation
files + special_files
end

##
# Tells if a feature is internal or external for Padrino project.
#
def external_feature?(file)
!file.start_with?(Padrino.root)
end

def constant_excluded?(const)
(exclude_constants - include_constants).any?{ |c| const._orig_klass_name.start_with?(c) }
end
Expand Down
6 changes: 3 additions & 3 deletions padrino-core/lib/padrino-core/reloader/storage.rb
Expand Up @@ -6,15 +6,15 @@ module Storage
def clear!
files.each_key do |file|
remove(file)
$LOADED_FEATURES.delete(file)
Reloader.remove_feature(file)
end
@files = {}
end

def remove(name)
file = files[name] || return
file[:constants].each{ |constant| Reloader.remove_constant(constant) }
file[:features].each{ |feature| $LOADED_FEATURES.delete(feature) }
file[:features].each{ |feature| Reloader.remove_feature(feature) }
files.delete(name)
end

Expand All @@ -27,7 +27,7 @@ def prepare(name)
}
features = file && file[:features] || []
features.each{ |feature| Reloader.safe_load(feature, :force => true) }
$LOADED_FEATURES.delete(name) if old_features.include?(name)
Reloader.remove_feature(name) if old_features.include?(name)
end

def commit(name)
Expand Down
1 change: 1 addition & 0 deletions padrino-core/test/fixtures/apps/helpers/support.rb
@@ -0,0 +1 @@
require 'active_support/logger_silence'

0 comments on commit 8e23d81

Please sign in to comment.