alexreisner / alexreisner/geocoder
Proposed solution to the AR includes problem
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 6.4k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
I would like to propose the following solution to the AR includes problem (see 'Known Issue' at the end of the README), and to open a discussion with Alex and the geocoder community.
Proposed solution:
- Remove the
:selectfrom the AR query. - Instead, add
distanceandbearinginstance methods to the AR model, to be calculated application-side. The formulae would translate easily into pure Ruby code.
This would primarily enable the includes scope to work correctly, but would also improve performance:
- The bearing is currently always calculated, but may not be required.
- The database must currently calculate the distance twice per row: once for the
SELECTand again for theORDER BY. - When used in conjunction with pagination, many of the calculated distances and bearings are discarded if they don't appear on the current page, only to be recalculated when the page changes.
Comments welcome.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Known Issue in README and the Active Record query in lib/geocoder/stores/active_record.rb around lines 160-162. Review the discussion and determine whether the proposed query and model-method changes have community agreement. Done requires an agreed design and a verified solution for the includes scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- backend, databases
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100