Skip to content

Loading…

Backport eager load to support Rails 3 #723

Merged
merged 2 commits into from

5 participants

@rafaelfranca

Since ActiveSupport::Autoload.eager_load! is not defined I think the
correct way is register the classes to be autoloaded and the
preload_framework initilizer will load all the classes registered.

@josevalim is it right?

Closes #478

@rafaelfranca

I think I'll need a way to load Inputs and Components before trigger the eager_load! initializer

@josevalim
Plataformatec member

Great job! In Rails 3, the eager load is global, so just using eager_autoload do...end should be enough to register it to be eager loaded. This code seems to be good but I'd create a Rails app on latest Rails 3.2 and ensure it boots in production just in case!

:heart:

@rafaelfranca rafaelfranca was assigned
@nashby

@rafaelfranca @josevalim I've just tested it in a new Rails 3.2.11 app in both production and dev mode. It works, so I think it's good to go! :shipit:

@rmascarenhas

I double-checked (just in case) and it does work, so I'm merging it :heart:

@rmascarenhas rmascarenhas merged commit 450d5e7 into master

1 check passed

Details default The Travis build passed
@rmascarenhas rmascarenhas deleted the rails_3_eager_load branch
@MrJaba

Is there anything I need to do to enable this behaviour? My initial request still has forms taking approx 150ms to render and then on subsequent requests they take ~4ms. I've upgraded to 2.1.0 which looks to have this commit in it.

Thanks!

@rafaelfranca

Yes, you have to enable config.threadsafe! in your application

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 2, 2013
  1. @rafaelfranca
  2. @rafaelfranca

    These modules don't need to be autoloaded

    rafaelfranca committed
    Conflicts:
    	lib/simple_form/form_builder.rb
Showing with 45 additions and 35 deletions.
  1. +11 −8 lib/simple_form.rb
  2. +12 −10 lib/simple_form/components.rb
  3. +1 −0 lib/simple_form/form_builder.rb
  4. +19 −17 lib/simple_form/inputs.rb
  5. +2 −0 lib/simple_form/inputs/base.rb
View
19 lib/simple_form.rb
@@ -6,14 +6,17 @@
require 'active_support/core_ext/hash/reverse_merge'
module SimpleForm
- autoload :Components, 'simple_form/components'
- autoload :ErrorNotification, 'simple_form/error_notification'
- autoload :FormBuilder, 'simple_form/form_builder'
- autoload :Helpers, 'simple_form/helpers'
- autoload :I18nCache, 'simple_form/i18n_cache'
- autoload :Inputs, 'simple_form/inputs'
- autoload :MapType, 'simple_form/map_type'
- autoload :Wrappers, 'simple_form/wrappers'
+ extend ActiveSupport::Autoload
+
+ autoload :Helpers
+ autoload :Wrappers
+
+ eager_autoload do
+ autoload :Components
+ autoload :ErrorNotification
+ autoload :FormBuilder
+ autoload :Inputs
+ end
## CONFIGURATION OPTIONS
View
22 lib/simple_form/components.rb
@@ -6,15 +6,17 @@ module SimpleForm
# to the input in order to be enabled. On the other hand, things like
# hints can generate output automatically by doing I18n lookups.
module Components
- autoload :Errors, 'simple_form/components/errors'
- autoload :Hints, 'simple_form/components/hints'
- autoload :HTML5, 'simple_form/components/html5'
- autoload :LabelInput, 'simple_form/components/label_input'
- autoload :Labels, 'simple_form/components/labels'
- autoload :MinMax, 'simple_form/components/min_max'
- autoload :Maxlength, 'simple_form/components/maxlength'
- autoload :Pattern, 'simple_form/components/pattern'
- autoload :Placeholders, 'simple_form/components/placeholders'
- autoload :Readonly, 'simple_form/components/readonly'
+ extend ActiveSupport::Autoload
+
+ autoload :Errors
+ autoload :Hints
+ autoload :HTML5
+ autoload :LabelInput
+ autoload :Labels
+ autoload :MinMax
+ autoload :Maxlength
+ autoload :Pattern
+ autoload :Placeholders
+ autoload :Readonly
end
end
View
1 lib/simple_form/form_builder.rb
@@ -1,4 +1,5 @@
require 'simple_form/core_ext/hash'
+require 'simple_form/map_type'
module SimpleForm
class FormBuilder < ActionView::Helpers::FormBuilder
View
36 lib/simple_form/inputs.rb
@@ -1,21 +1,23 @@
module SimpleForm
module Inputs
- autoload :Base, 'simple_form/inputs/base'
- autoload :BlockInput, 'simple_form/inputs/block_input'
- autoload :BooleanInput, 'simple_form/inputs/boolean_input'
- autoload :CollectionCheckBoxesInput, 'simple_form/inputs/collection_check_boxes_input'
- autoload :CollectionInput, 'simple_form/inputs/collection_input'
- autoload :CollectionRadioButtonsInput, 'simple_form/inputs/collection_radio_buttons_input'
- autoload :CollectionSelectInput, 'simple_form/inputs/collection_select_input'
- autoload :DateTimeInput, 'simple_form/inputs/date_time_input'
- autoload :FileInput, 'simple_form/inputs/file_input'
- autoload :GroupedCollectionSelectInput, 'simple_form/inputs/grouped_collection_select_input'
- autoload :HiddenInput, 'simple_form/inputs/hidden_input'
- autoload :NumericInput, 'simple_form/inputs/numeric_input'
- autoload :PasswordInput, 'simple_form/inputs/password_input'
- autoload :PriorityInput, 'simple_form/inputs/priority_input'
- autoload :RangeInput, 'simple_form/inputs/range_input'
- autoload :StringInput, 'simple_form/inputs/string_input'
- autoload :TextInput, 'simple_form/inputs/text_input'
+ extend ActiveSupport::Autoload
+
+ autoload :Base
+ autoload :BlockInput
+ autoload :BooleanInput
+ autoload :CollectionCheckBoxesInput
+ autoload :CollectionInput
+ autoload :CollectionRadioButtonsInput
+ autoload :CollectionSelectInput
+ autoload :DateTimeInput
+ autoload :FileInput
+ autoload :GroupedCollectionSelectInput
+ autoload :HiddenInput
+ autoload :NumericInput
+ autoload :PasswordInput
+ autoload :PriorityInput
+ autoload :RangeInput
+ autoload :StringInput
+ autoload :TextInput
end
end
View
2 lib/simple_form/inputs/base.rb
@@ -1,3 +1,5 @@
+require 'simple_form/i18n_cache'
+
module SimpleForm
module Inputs
class Base
Something went wrong with that request. Please try again.