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

Countries call is ridiculously slow. Switch to async #11

Open
hhff opened this issue Apr 19, 2015 · 5 comments
Open

Countries call is ridiculously slow. Switch to async #11

hhff opened this issue Apr 19, 2015 · 5 comments

Comments

@hhff
Copy link
Owner

hhff commented Apr 19, 2015

No description provided.

@hhff
Copy link
Owner Author

hhff commented Apr 20, 2015

or introduce cacheing?

@felixbuenemann
Copy link

There are several issues here:

  • 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.

@felixbuenemann
Copy link

Btw. pulling all countries and states amounts to roughly 10 MBytes of JSON uncompressed.

@hhff
Copy link
Owner Author

hhff commented Mar 7, 2016

Haha yeah I know - it's totally ridiculous @felixbuenemann !

I'd love a PR for this!

@felixbuenemann
Copy link

Done, see PR #29.

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

No branches or pull requests

2 participants