0
votes
class User < ApplicationRecord
  has_many :buckets, -> { order(ranked_row: :asc) }
  delegate :incomes, :fixed_costs, :financial_goals, to: :buckets

  ...
end

I have Buckets, that are STI'd. If I add that scope to the has_many, my page takes forever on 9 records, and seems to be loading something that should be cached

74s...

If I remove the scope, all is well

3s...

Any idea how the scope on the has_many is affecting the STI?? ranked_row has an index, but it's the same, regardless. I am using active_model_serializers, but I'm not sure if there's a correlation.

Update

Definitely something with active_model_serializers. ActiveModel::SerializableResource.new(user) is in the controller, and bogs down in the console, too. I removed everything from the from the serializer, and calling the scoped has_many is the thing. I'll hit up github.

Code

https://gist.github.com/dudo/f25767f00c874842a005

That's the smallest bit of code I could get to cause the issue. Again, It works fine without the scope on the has_many, and it also works with removing the percent_complete method from Bucket... that method doesn't look too nasty. What could be in that included_transactions method that's bringing it to a crawl when a scope is present??

1
does the behavior change when you remove the delegation? i'd try to create a minimal set to reproduce this and report a bug edgeguides.rubyonrails.org/…phoet
doesn't appear so. I changed them to individual has_many, same thing.Dudo
I think the problem can be in models/bucket.rb. Source or it did not happen.gizmore
Have your source. I found the method that is causing the problem, but I have no idea why.Dudo
what happens if you eager-load the bucket and user relations?phoet

1 Answers

1
votes