Skip to content

Commit

Permalink
Merge pull request #533 from LACMTA:2023-api-optimization
Browse files Browse the repository at this point in the history
Refactor get_route_details function to use JSON deserialization for geometries
  • Loading branch information
albertkun authored May 22, 2024
2 parents f55d534 + 8021f1a commit f4a9f0a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fastapi/app/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,15 @@ async def get_route_details(db: AsyncSession, route_code: str, direction_id: int
# Extract shape_ids from stop_times
shape_ids = {shape_id for stop in stop_times for shape_id in stop[1]['shape_ids']}


query = text("SELECT shape_id, ST_AsGeoJSON(geometry) FROM metro_api.trip_shapes WHERE shape_id IN :shape_ids")
result = db.execute(query, {'shape_ids': tuple(shape_ids)})

# Fetch all rows from the result
geometries_result = result.fetchall()

# Process the geometries
geometries = {shape_id: geometry for shape_id, geometry in geometries_result}
geometries = {shape_id: json.loads(geometry) for shape_id, geometry in geometries_result}

# Prepare the debugging information
debug_info = {
Expand Down

0 comments on commit f4a9f0a

Please sign in to comment.