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

Improve response time of Shops page #12520

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thejwuscript
Copy link
Contributor

What? Why?

Explanation

Possible Cause

One possible cause of the slow performance is the execution of multiple database queries to fetch distributed_properties for each active shop (2 or 3 queries per active shop).

Solutions Considered

  1. Caching
    1. Extending the cache duration for shops data by increasing the SHOPS_EXPIRY value can be considered. The value is currently set to 15 seconds. I think it could be extended depending on how important it is show shops open/closed status accurately on this page. We can also consider telling users on the page “shops info is updated every x minutes” or something to that effect.
  2. Asynchronous loading
    1. The initial page view does not show enterprise or product properties, so it might not be necessary to fetch associated distributed_properties prior to the initial page load. We could probably fetch them via AJAX request, but this may require significant code refactoring.
  3. Optimize Active Record Query
    1. It seems like there are 2 or 3 database queries just to get distributed_properties per active shop, so there is a bit of room for optimization. The best query I could come up with is to combine the queries in distributed_product_properties and distributed_producer_properties methods into one long chain. This was tested and it reduces the response time by roughly 33%.
    2. This was implemented in this PR.
  4. Pagination or Infinite Scrolling

What should we test?

There should be no regression or changes in behavior of the /shops page.

To test the performance:

  1. On the master branch, visit /shops and take note of the request processing time from the logs.
  2. Checkout this PR branch
  3. Create at least 100 active shops (the more the better)
  4. Visit /shops again and compare the request processing time.

Release notes

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

  • Technical changes only

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

@sigmundpetersen
Copy link
Contributor

Hey @thejwuscript , there are a couple of CI failures.
Could you have a look before we put this into code review? Thanks

@thejwuscript thejwuscript marked this pull request as draft May 30, 2024 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress ⚙
Development

Successfully merging this pull request may close these issues.

Improve response times of shops#index
2 participants