-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slow app boot when trying to observe ActiveRecord::Base #35
Comments
Just as Google food: in our case, we (I'm on the same team as @joakimk) noticed this as Resque workers taking a long time to boot (several minutes) after upgrading from Rails 3 to Rails 4 and switching to rails-observers. |
The list of observed models seems to grow exponentially, containing each model many times (duplicates). It is apparently solved by putting |
👍 |
* This was happening when a subclass of an observed class was created. * The subclass was being observed twice. * I've changed one of the tests to catch this.
…ails#35. * Subclasses were being observed (via add_observer) but not added to observed_classes * Added call to observe() in initialize to update observed_classes * Moved searching of descendants to initialize, so the comment "Start observing the declared classes and their subclasses." will be correct for all subclasses of ActiveModel::Observer (not just ActiveRecord::Observer) * Removed ActiveRecord::Observer#observed_classes, as descendants are now searched on initialize (this was the main cause of rails#35) * No need for models.uniq! in #observe (undoing previous commit) * Improved tests to better cover uniqueness of observed_classes * Tests don't work with minitest 5.8.0; require < 5
@anthonyjsmith Do you consider this issue solved? Just wondering if we can remove https://github.com/barsoom/reproduce_observer_error. |
It's been a few years, and I'm not working with Rails any more, so my memory is a bit hazy, but yes, I consider it solved. |
... although the pull request seems to still be open, so maybe it isn't fully solved yet...? #36 |
Definitely not resolved yet, it takes us like 20 seconds to load each constant. Stack trace is always in this code:
|
Do not observe the same model more than once. copied from https://github.com/rails/rails-observers/pull/36/files
Do not observe the same model more than once. copied from https://github.com/rails/rails-observers/pull/36/files
If you observe
ActiveRecord::Base
in order to do something if any model is changed there is some bug in how the observers lists are created causing the app boot to take a long time when eager loading code.In our case we had an observer that removed comments if a model was destroyed and it had associated comments.
I've reproduced the issue here: https://github.com/barsoom/reproduce_observer_error
We don't use observers in any apps anymore, but thought I'd post this in case someone else had the same issue.
The text was updated successfully, but these errors were encountered: