Skip to content
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

HasMany relationships load all objects and then count on collection page #1464

Closed
RCulpepp opened this issue Nov 8, 2019 · 3 comments
Closed
Labels
bug breakages in functionality that is implemented dashboards how administrate presents fields and displays data

Comments

@RCulpepp
Copy link

RCulpepp commented Nov 8, 2019

  • What were you trying to do?
    I was attempting to load an index of resources that had hundreds of thousands of associated resources through a has_many relationship. When querying, it is attempting to load all objects in memory, before counting. Thus slowing down the app (unnecessarily and unexpectedly) since all that displays is a count for those associated objects.

I have something like this:

resource_dashboard.rb

ATTRIBUTE_TYPES = {
  associated_resources: Field::HasMany
}.freeze

COLLECTION_ATTRIBUTES = [
  :associated_resources,
].freeze
  • What did you end up with (logs, or, even better, example apps are great!)?
    A very slow response!

I've come up with a solution that'll I'll submit as a PR.

  • What versions are you running?
    • Rails 5.0.7.2
    • administrate 0.11.0
@RCulpepp RCulpepp added the bug breakages in functionality that is implemented label Nov 8, 2019
@nickcharlton nickcharlton added the dashboards how administrate presents fields and displays data label Jan 2, 2020
@pablobm
Copy link
Collaborator

pablobm commented Apr 23, 2021

I think this is the same as #1464. I'm closing this one as the other one has more discussion and detail.

@pablobm pablobm closed this as completed Apr 23, 2021
@gabriel
Copy link

gabriel commented Nov 17, 2021

You referenced this issue (#1464), did you mean to point to a different one?

@pablobm
Copy link
Collaborator

pablobm commented Nov 18, 2021

Ooops. And not the first time I do this either 😓

I'm not sure which issue I meant to link to. It might be #1697, where I offer a potential solution that I'll quote here:

Perhaps this should be solved outside Administrate? I'm thinking of using the counter_cache option to belongs_to, and show this in the index page, instead of the HasMany field. See: https://guides.rubyonrails.org/association_basics.html#options-for-belongs-to-counter-cache

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug breakages in functionality that is implemented dashboards how administrate presents fields and displays data
Projects
None yet
Development

No branches or pull requests

4 participants