Open
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
:select
from the AR query. - Instead, add
distance
andbearing
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 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.