Skip to content

Speedup countries#29

Open
felixbuenemann wants to merge 2 commits intohhff:3-0-alphafrom
felixbuenemann:speedup-countries
Open

Speedup countries#29
felixbuenemann wants to merge 2 commits intohhff:3-0-alphafrom
felixbuenemann:speedup-countries

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