Skip to content

Commit d1ed5af

Browse files
committed
linked feeds if they share at least one location
1 parent 136613f commit d1ed5af

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

api/src/shared/db_models/gtfs_rt_feed_impl.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,19 @@ def from_orm(cls, feed: Gtfsrealtimefeed | None, db_session: Session) -> GtfsRTF
3030
# gtfs_rt_feed.feed_references = [item.stable_id for item in feed.gtfs_feeds] if feed.gtfs_feeds else []
3131
gtfs_rt_location_ids = {location.id for location in feed.locations}
3232
query = (
33-
db_session.query(FeedOrm).filter(FeedOrm.provider == feed.provider).options(joinedload(FeedOrm.locations))
33+
db_session.query(FeedOrm)
34+
.filter(FeedOrm.provider == feed.provider, FeedOrm.stable_id != feed.stable_id)
35+
.options(joinedload(FeedOrm.locations))
3436
)
3537

3638
feed_references = []
3739
for gtfs_feed in query.all():
3840
gtfs_location_ids = {location.id for location in gtfs_feed.locations}
39-
if gtfs_location_ids.issubset(gtfs_rt_location_ids):
41+
# Check if there is any overlap in locations.
42+
if not gtfs_location_ids.isdisjoint(gtfs_rt_location_ids):
4043
feed_references.append(gtfs_feed.stable_id)
4144
gtfs_rt_feed.feed_references = feed_references
45+
4246
return gtfs_rt_feed
4347

4448
@classmethod

0 commit comments

Comments
 (0)