Browse Source

Immensely speed up the address lookups by using spatial comparison

feature/region-slug-gone
Bèr Kessels 5 months ago
parent
commit
d940d0bb04
1 changed files with 2 additions and 14 deletions
  1. 2
    14
      app/aggregates/place/address.rb

+ 2
- 14
app/aggregates/place/address.rb View File

@@ -45,9 +45,7 @@ module Hours

# Fallback to setting the memoized @address to empty hash to avoid
# re-looking up a nonexisting address
@address = dataset.select_append(sql_distance)
.order(:distance)
.first(sql_within) || {}
@address = dataset.order(sql_distance).first || {}
end

def point
@@ -57,17 +55,7 @@ module Hours
end

def sql_distance
Sequel.lit(
'ST_Distance(location::geography, ?::geography) as distance',
point
)
end

def sql_within
Sequel.lit(
'ST_DWithin(location::geography, ?::geography, ?)',
point, DISTANCE_MARGIN
)
Sequel.lit('location <-> ?', point)
end
end
end

Loading…
Cancel
Save