Skip to content

Commit

Permalink
DB.Resource.get_related_conversion_info : utilise l'index SQL (#4450)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti authored Feb 18, 2025
1 parent e616e02 commit 1fb477d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions apps/transport/lib/db/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ defmodule DB.Resource do

def get_related_conversion_info(resource_id, format) do
converter = DB.DataConversion.converter_to_use(format)
# Only value supported for now but needed to make the query fast
# https://github.com/etalab/transport-site/issues/4448
convert_from = :GTFS

DB.ResourceHistory
|> join(:inner, [rh], dc in DB.DataConversion,
Expand All @@ -237,8 +240,9 @@ defmodule DB.Resource do
})
|> where(
[rh, dc],
rh.resource_id == ^resource_id and dc.convert_to == ^format and dc.status == :success and
dc.converter == ^converter
rh.resource_id == ^resource_id and
dc.convert_from == ^convert_from and dc.convert_to == ^format and
dc.status == :success and dc.converter == ^converter
)
|> order_by([rh, _], desc: rh.inserted_at)
|> limit(1)
Expand Down

0 comments on commit 1fb477d

Please sign in to comment.