Skip to content

Commit

Permalink
fixup: add indexes for latitude/longitude
Browse files Browse the repository at this point in the history
  • Loading branch information
rudiejd committed Dec 19, 2024
1 parent 441b900 commit cba0430
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/arrow/gtfs/stop.ex
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ defmodule Arrow.Gtfs.Stop do
from(s in Arrow.Gtfs.Stop,
where:
s.lat <= ^lat + @latitude_degrees_per_mile and
s.lat >= ^lat - @latitude_degrees_per_mile and
s.lon <= ^lon + @longitude_degrees_per_mile and
s.lon >= ^lon - @latitude_degrees_per_mile
s.lat >= ^lat - @latitude_degrees_per_mile and
s.lon <= ^lon + @longitude_degrees_per_mile and
s.lon >= ^lon - @latitude_degrees_per_mile and
s.vehicle_type == :bus
)
|> Repo.all()
end
Expand Down
8 changes: 8 additions & 0 deletions priv/repo/migrations/20241219160941_add_indexes_lat_lon.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule Arrow.Repo.Migrations.AddIndexesLatLon do
use Ecto.Migration

def change do
create index(:gtfs_stops, [:lat, :lon, :vehicle_type, :id])
create index(:stops, [:stop_lat, :stop_lon, :stop_id])
end
end
15 changes: 15 additions & 0 deletions priv/repo/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,13 @@ CREATE INDEX disruption_notes_disruption_id_index ON public.disruption_notes USI
CREATE INDEX disruption_trip_short_names_disruption_id_index ON public.disruption_trip_short_names USING btree (disruption_revision_id);


--
-- Name: gtfs_stops_lat_lon_vehicle_type_id_index; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX gtfs_stops_lat_lon_vehicle_type_id_index ON public.gtfs_stops USING btree (lat, lon, vehicle_type, id);


--
-- Name: oban_jobs_args_index; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1444,6 +1451,13 @@ CREATE UNIQUE INDEX shuttles_shuttle_name_index ON public.shuttles USING btree (
CREATE UNIQUE INDEX stops_stop_id_index ON public.stops USING btree (stop_id);


--
-- Name: stops_stop_lat_stop_lon_stop_id_index; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX stops_stop_lat_stop_lon_stop_id_index ON public.stops USING btree (stop_lat, stop_lon, stop_id);


--
-- Name: unique_disruption_weekday; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1761,3 +1775,4 @@ INSERT INTO public."schema_migrations" (version) VALUES (20241029192033);
INSERT INTO public."schema_migrations" (version) VALUES (20241030181351);
INSERT INTO public."schema_migrations" (version) VALUES (20241209204043);
INSERT INTO public."schema_migrations" (version) VALUES (20241210155455);
INSERT INTO public."schema_migrations" (version) VALUES (20241219160941);

0 comments on commit cba0430

Please sign in to comment.