|
3 | 3 | from sqlalchemy import text |
4 | 4 | from shared.database_gen.sqlacodegen_models import Gtfsdataset, Feed, t_feedsearch |
5 | 5 | from shared.database.database import refresh_materialized_view |
| 6 | +from typing import TYPE_CHECKING |
| 7 | + |
| 8 | +if TYPE_CHECKING: |
| 9 | + from sqlalchemy.orm import Session |
| 10 | + |
6 | 11 |
|
7 | 12 | # query to update the status of the feeds based on the service date range of the latest dataset |
8 | 13 | def update_feed_statuses_query(session: "Session", stable_feed_ids: list[str]): |
@@ -41,24 +46,25 @@ def update_feed_statuses_query(session: "Session", stable_feed_ids: list[str]): |
41 | 46 | try: |
42 | 47 | diff_counts: dict[str, int] = {} |
43 | 48 |
|
44 | | - filters = [ |
45 | | - Feed.id == latest_dataset_subq.c.feed_id, |
46 | | - Feed.status != text("'deprecated'::status"), |
47 | | - Feed.status != text("'development'::status"), |
48 | | - # We filter out feeds that already have the status so that the |
49 | | - # update count reflects the number of feeds that actually |
50 | | - # changed status. |
51 | | - Feed.status != text("'%s'::status" % status), |
52 | | - service_date_conditions, |
53 | | - ] |
| 49 | + def get_filters(status: str): |
| 50 | + filters = [ |
| 51 | + Feed.id == latest_dataset_subq.c.feed_id, |
| 52 | + Feed.status != text("'deprecated'::status"), |
| 53 | + Feed.status != text("'development'::status"), |
| 54 | + # We filter out feeds that already have the status so that the |
| 55 | + # update count reflects the number of feeds that actually |
| 56 | + # changed status. |
| 57 | + Feed.status != text("'%s'::status" % status), |
| 58 | + service_date_conditions, |
| 59 | + ] |
54 | 60 |
|
55 | | - if len(stable_feed_ids) > 0: |
56 | | - filters.append(Feed.stable_feed_id.in_(stable_feed_ids)) |
| 61 | + if len(stable_feed_ids) > 0: |
| 62 | + filters.append(Feed.stable_feed_id.in_(stable_feed_ids)) |
57 | 63 |
|
58 | 64 | for service_date_conditions, status in status_conditions: |
59 | 65 | diff_counts[status] = ( |
60 | 66 | session.query(Feed) |
61 | | - .filter(*filters) |
| 67 | + .filter(*get_filters(status)) |
62 | 68 | .update({Feed.status: status}, synchronize_session=False) |
63 | 69 | ) |
64 | 70 | except Exception as e: |
|
0 commit comments