Skip to content

Proposed solution to the AR includes problem #99

Open
@gjb83

Description

@gjb83

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions