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,8 +25,10 @@ returns
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def self.all
|
def self.all
|
||||||
|
@all ||= begin
|
||||||
all = {}
|
all = {}
|
||||||
dir = Rails.root.join('app', 'models').to_s
|
dir = Rails.root.join('app', 'models').to_s
|
||||||
|
tables = ActiveRecord::Base.connection.tables
|
||||||
Dir.glob("#{dir}/**/*.rb") do |entry|
|
Dir.glob("#{dir}/**/*.rb") do |entry|
|
||||||
next if entry.match?(/application_model/i)
|
next if entry.match?(/application_model/i)
|
||||||
next if entry.match?(%r{channel/}i)
|
next if entry.match?(%r{channel/}i)
|
||||||
|
@ -41,7 +43,7 @@ returns
|
||||||
next if !model_class.respond_to? :new
|
next if !model_class.respond_to? :new
|
||||||
next if !model_class.respond_to? :table_name
|
next if !model_class.respond_to? :table_name
|
||||||
table_name = model_class.table_name # handle models where not table exists, pending migrations
|
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
|
model_object = model_class.new
|
||||||
next if !model_object.respond_to? :attributes
|
next if !model_object.respond_to? :attributes
|
||||||
all[model_class] = {}
|
all[model_class] = {}
|
||||||
|
@ -54,6 +56,7 @@ returns
|
||||||
end
|
end
|
||||||
all
|
all
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue