This project is archived and is in readonly mode.
[PATCH] AutosaveAssociation generates unneeded validations
Reported by Alexey Kovyrin | September 7th, 2009 @ 08:59 PM
For models with many (tens, hundreds) associations Rails after 5cda000b would generate tons of dummy validation methods (one per association) that would call validate_collection_association/validate_single_association methods to figure out if any validations needed at all.
In our project with hundreds of highly-relational models (some models have 50+ associations) this behavior causes the application code to work significantly slower (tests execution time x 1.5, some controllers actions work 4x slower).
Aside from the performance degradation there is another problem: according to official Rails documentation, there are few different cases in association validations behavior:
has_many
associations are validated by default (:validate
option is true by default)- all other associations have
:validate
set to false by default - any association could be switched to validation mode by adding :validate => true to the declaration
In my patch and tests I've changed the way Rails generate validation methods to make it work in accordingly. If an association does not need to be validated, there is no need to generate a method for it and call this callback method for each validation.
Comments and changes to this ticket
-
Dmytro Shteflyuk September 7th, 2009 @ 10:39 PM
Alexey, thank you for your great work. I think this is serious problem and performance degradation is not acceptable. Some of our actions performed more than 2 times slower than in Rails 2.1.
Hope, core team will accept your patch in a short time, until then we will use patched Rails.
-
Eloy Duran September 9th, 2009 @ 09:43 AM
The patch looks great Alexey, thanks! I'll take some time later this week to apply to my branch and rebaseetc, so I can get the whole branch applied upstream.
-
Repository September 13th, 2009 @ 02:33 AM
- State changed from new to resolved
(from [c0245493cb9316b2c92ee4a02e71de557eb31ff2]) Define autosave association validation methods only when needed. [#3161 state:resolved]
Signed-off-by: Eloy Duran eloy.de.enige@gmail.com
http://github.com/rails/rails/commit/c0245493cb9316b2c92ee4a02e71de... -
Repository September 13th, 2009 @ 02:33 AM
(from [938c0ee0455b8e784a771ce31631d9ec376ee6ab]) Define autosave association validation methods only when needed. [#3161 state:resolved]
Signed-off-by: Eloy Duran eloy.de.enige@gmail.com
http://github.com/rails/rails/commit/938c0ee0455b8e784a771ce31631d9... -
Tom Stuart October 8th, 2009 @ 04:41 PM
This change breaks validation of autosave associations in some circumstances. See #3355.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 3161 [PATCH] AutosaveAssociation generates unneeded validations (from [c0245493cb9316b2c92ee4a02e71de557eb31ff2]) Define ...
- 3161 [PATCH] AutosaveAssociation generates unneeded validations (from [938c0ee0455b8e784a771ce31631d9ec376ee6ab]) Define ...
- 3355 Validation of autosaved associations is broken This commit from #3161 broke validation of autosaved ass...
- 3355 Validation of autosaved associations is broken The change in #3161 leaves accepts_nested_attributes_for ...