Skip to content

Commit

Permalink
optimize agg queries (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
OriHoch authored Dec 4, 2023
1 parent b212a33 commit 47ede7e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion open_bus_stride_api/routers/gtfs_rides_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ def list_(limit: int = common.param_limit(default_limit=DEFAULT_LIMIT),
where
agg.gtfs_route_id = rt.id
and agg.gtfs_route_date >= :date_from
and agg.gtfs_route_date <= :date_to
and agg.gtfs_route_date <= :date_to
and rt.date >= :rt_date_from
and rt.date <= :rt_date_to
"""
sql_params = {
'date_from': date_from,
'date_to': date_to,
'rt_date_from': date_from - datetime.timedelta(days=1),
'rt_date_to': date_from + datetime.timedelta(days=1),
}

if exclude_hours_from:
Expand Down Expand Up @@ -116,10 +120,14 @@ def group_by_(date_from: datetime.date = common.doc_param('date', filter_type='d
agg.gtfs_route_id = rt.id
and agg.gtfs_route_date >= :date_from
and agg.gtfs_route_date <= :date_to
and rt.date >= :rt_date_from
and rt.date <= :rt_date_to
""")
sql_params = {
'date_from': date_from,
'date_to': date_to,
'rt_date_from': date_from - datetime.timedelta(days=1),
'rt_date_to': date_from + datetime.timedelta(days=1),
}

if exclude_hours_from:
Expand Down

0 comments on commit 47ede7e

Please sign in to comment.