Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 1b9445a

Browse files
committed
fix guard
1 parent d03638c commit 1b9445a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/hyper-operation/transport/policy.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ def get_ar_model(str)
9999
end
100100
str
101101
else
102-
if Rails.env.production? && Hyperloop::InternalClassPolicy.ar_base_descendants_map_cache.include?(str)
102+
# we used to cache this here, but during eager loading the cache may get partially filled and never updated
103+
# so this guard will fail, now performance will be suckish, as this guard, required for security, takes some ms
104+
# def self.ar_base_descendants_map_cache
105+
# @ar_base_descendants_map_cache ||= ActiveRecord::Base.descendants.map(&:name)
106+
# end
107+
# if Rails.env.production? && !Hyperloop::InternalClassPolicy.ar_base_descendants_map_cache.include?(str)
108+
if Rails.application.config.eager_load && !ActiveRecord::Base.descendants.map(&:name).include?(str)
103109
# AR::Base.descendants is eager loaded in production -> this guard works.
104110
# In development it may be empty or partially filled -> this guard may fail.
105111
# Thus guarded here only in production.

0 commit comments

Comments
 (0)