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

Speedup countries #29

Open
wants to merge 2 commits into
base: 3-0-alpha
Choose a base branch
from

Conversation

felixbuenemann
Copy link

  • Use @countries.includes(:states) to avoid n+1 queries on states
  • Drop the has_one :country on the StateSerializer and replace with attribute :country_id to avoid n+1 queries for the country
  • Including all the countries might not be needed in most cases, so it's possible to add a query param to filter by country codes (eg.: api/ams/countries?isos[]=DE&isos[]=CH&isos[]=AT)

Doing the first two brings down load time from > 30s to ~5s, the last example takes < 100ms.

Related to issue #11.

Example:
`curl http://localhost:3000/api/ams/countries\?isos\=DE,CH,AT`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant