Skip to content

Commit a70d5cf

Browse files
committed
Eager load the constants
In a thread-based backend like Sidekiq, there is a possibility that autoload may occur simultaneously in multiple threads, and as a result, it is presumed that an error may be caused by contention of autoload. In order to avoid the above issue, eager load the constants on boot. Maybe fixes #101
1 parent b7c5f6d commit a70d5cf

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/global_id.rb

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
require 'global_id/global_id'
2+
require 'active_support'
23

34
autoload :SignedGlobalID, 'global_id/signed_global_id'
45

56
class GlobalID
6-
autoload :Locator, 'global_id/locator'
7-
autoload :Identification, 'global_id/identification'
8-
autoload :Verifier, 'global_id/verifier'
7+
extend ActiveSupport::Autoload
8+
9+
eager_autoload do
10+
autoload :Locator
11+
autoload :Identification
12+
autoload :Verifier
13+
end
914
end

lib/global_id/railtie.rb

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class GlobalID
1111
# Set up the signed GlobalID verifier and include Active Record support.
1212
class Railtie < Rails::Railtie # :nodoc:
1313
config.global_id = ActiveSupport::OrderedOptions.new
14+
config.eager_load_namespaces << GlobalID
1415

1516
initializer 'global_id' do |app|
1617

0 commit comments

Comments
 (0)