Improved performance by caching the result process wide instead of globing and accessing the database multiple times.
This commit is contained in:
parent
38d757c65b
commit
57294646a9
1 changed files with 29 additions and 26 deletions
|
@ -25,9 +25,11 @@ returns
|
|||
=end
|
||||
|
||||
def self.all
|
||||
@all ||= begin
|
||||
all = {}
|
||||
dir = Rails.root.join('app', 'models').to_s
|
||||
Dir.glob("#{dir}/**/*.rb" ) do |entry|
|
||||
tables = ActiveRecord::Base.connection.tables
|
||||
Dir.glob("#{dir}/**/*.rb") do |entry|
|
||||
next if entry.match?(/application_model/i)
|
||||
next if entry.match?(%r{channel/}i)
|
||||
next if entry.match?(%r{observer/}i)
|
||||
|
@ -41,7 +43,7 @@ returns
|
|||
next if !model_class.respond_to? :new
|
||||
next if !model_class.respond_to? :table_name
|
||||
table_name = model_class.table_name # handle models where not table exists, pending migrations
|
||||
next if !ActiveRecord::Base.connection.tables.include?(table_name)
|
||||
next if !tables.include?(table_name)
|
||||
model_object = model_class.new
|
||||
next if !model_object.respond_to? :attributes
|
||||
all[model_class] = {}
|
||||
|
@ -54,6 +56,7 @@ returns
|
|||
end
|
||||
all
|
||||
end
|
||||
end
|
||||
|
||||
=begin
|
||||
|
||||
|
|
Loading…
Reference in a new issue