Skip to content
Snippets Groups Projects
Commit 523ab260 authored by Alex Rakoczy's avatar Alex Rakoczy
Browse files

Limit maxmind local subselect query to reduce cost

Since we only want to select one IP block anyway, limiting this query
reduces the query cost from (cost=22531.65..22539.67 rows=1 width=31)
to (cost=0.53..8.54 rows=1 width=31)
parent 3a362ba7
No related branches found
No related tags found
No related merge requests found
......@@ -36,7 +36,7 @@ module Geocoder::Lookup
addr = IPAddr.new(query.text).to_i
q = "SELECT l.country, l.region, l.city, l.latitude, l.longitude
FROM maxmind_geolite_city_location l WHERE l.loc_id = (SELECT b.loc_id FROM maxmind_geolite_city_blocks b
WHERE b.start_ip_num <= #{addr} AND #{addr} <= b.end_ip_num)"
WHERE b.start_ip_num <= #{addr} AND #{addr} <= b.end_ip_num LIMIT 1)"
format_result(q, [:country_name, :region_name, :city_name, :latitude, :longitude])
elsif configuration[:package] == :country
addr = IPAddr.new(query.text).to_i
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment