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

Preload enterprise distributed_properties for /shops page #12724

Closed

Conversation

johansenja
Copy link
Contributor

@johansenja johansenja commented Aug 1, 2024

What? Why?

When visiting https://openfoodnetwork.org.uk/shops, the page load is very slow. Given that this page is linked to from the
CTA above the fold on https://openfoodnetwork.org.uk/, it seems ideal that should load quickly.

Here, I have moved distributed_producer_properties and distributed_product_properties out of the enterprise serialiser and into the model (IMO a serialiser shouldn't be making new queries to the DB anyway), and defined them as associations so that they can be preloaded. This should improve on the n+2 situation as visible here (in green):

Screenshot 2024-08-01 at 14 26 05

There is potentially further that one could go (defining just a single distributed_properties has_many relationship), but I'm not sure if it's worth it, or about any other intricacies about how it is used.

What should we test?

  • Visit /shops page
  • Check page performance

I haven't been able to test this on a representative data set locally, so I'm unable to confirm how much of an impact this has!

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

Dependencies

It's similar to #12723, but doesn't depend on it directly

Documentation updates

@johansenja johansenja changed the title Preload enterprise logos and promo images for /shops page Preload enterprise distributed_properties and for /shops page Aug 1, 2024
@johansenja johansenja force-pushed the optimise-shops-page4 branch 2 times, most recently from ab04a5d to ffd31b3 Compare August 1, 2024 15:09
@johansenja johansenja changed the title Preload enterprise distributed_properties and for /shops page Preload enterprise distributed_properties for /shops page Aug 1, 2024
Comment on lines +386 to +390
def distributed_properties
(distributed_product_properties + distributed_producer_properties).uniq do |property_object|
property_object.property.presentation
end
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in the PR description, this could potentially be done one the DB level too because it might make things simpler - but I suppose I don't have enough knowledge on how this is used so far

@johansenja
Copy link
Contributor Author

Closing because I think there are better solutions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant