alexreisner / alexreisner/geocoder

Proposed solution to the AR includes problem

Open
#99 36 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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:

  1. Remove the :select from the AR query.
  2. Instead, add distance and bearing instance 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 SELECT and again for the ORDER 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.