There are always more than one way to put together an app, but I can give my experience.
- I acquired a set of data including IPs associated with a Discourse forum (~250K accts).
- I wrote PHP code (*note, not Ruby) to parse CSV and insert data into a MySQL database (*note, not PostgreSQL).
- I downloaded the deprecated MaxMind geolocation database
- I wrote code to do INET array ↔ number conversions and inserted values into the database
- I matched individual Discourse IPs to corresponding MaxMind Locations (even in limited numbers, eg. 10K accts, this step could take upwards of two hours to run - an expensive range select)
Once I had “base” data, I needed to only update with what was new since the last. It never took more than several minutes to run an [weekly] update.
Once I had the data I was interested in, running queries by location was not slow.