-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Use size instead of count for has many field #266
Use size instead of count for has many field #266
Conversation
4036cdd
to
9a1acd1
Compare
This looks good to me! I want to take a look and see if there are any other places we can make this change, but it should be about good to go. |
I think there's a few other instances where |
Great! I'm going to merge this as soon as I get off my flight tomorrow. |
Waiting on #294. |
Merged in as fd490db. Thanks! |
Changes: ``` * [#251] [FEATURE] Raise a helpful error when an attribute is missing from `ATTRIBUTE_TYPES` * [#298] [FEATURE] Support ActiveRecord model I18n translations * [#312] [FEATURE] Add a `nil` option to `belongs_to` form fields * [#231] [UI] Fix layout issue on show page where a long label next to an empty value would cause following fields on the page to be mis-aligned. * [#309] [UI] Fix layout issue in datetime pickers where months and years would not wrap correctly. * [#306] [UI] Wrap long text lines (on word breaks) on show pages * [#214] [UI] Improve header layout when there is a long page title * [#198] [UI] Improve spacing around bottom link in sidebar * [#206] [UI] Left-align checkboxes in boolean form fields * [#315] [UI] Remove the `IDS` suffix for `HasMany` form field labels * [#259] [BUGFIX] Make installation generator more robust by ignoring dynamically generated, unnamed models * [#243] [BUGFIX] Fix up a "Show" button on the edit page that was not using the `display_resource` method. * [#248] [BUGFIX] Improve polymorphic relationship's dashboard class detection. * [#247] [BUGFIX] Populate `has_many` and `belongs_to` select boxes with the current value of the relationship. * [#217] [I18n] Dutch * [#263] [I18n] Swedish * [#272] [I18n] Danish * [#270] [I18n] Don't apologize about missing relationship support. * [#237] [I18n] Fix broken paths for several I18n files (de, es, fr, pt-BR, vi). * [#266] [OPTIM] Save a few database queries by using cached counts ```
@Graysonwright - I get "ActionView::Template::Error: undefined method `size' for nil:NilClass". |
To help improve the admin performance, I noticed that there was a long string of
#count
queries going on; see before for the issue. The odd part to me was that I was doing this in my code:Course.includes(:videos)
and yet there was a constant call to#count
going on. Since the AR association is already loaded, why go back to PG? Switched from using#count
to#size
so that AR can intelligently load up the data and call count if its not there or, if it is there, just use ruby.Before:
After:
Reference: http://batsov.com/articles/2014/02/17/the-elements-of-style-in-ruby-number-13-length-vs-size-vs-count/