Skip to content

refactor: remove routesMap and migrate route lookups to DB#815

Open
Ahmedhossamdev wants to merge 2 commits intomainfrom
refactor/remove-routes-map
Open

refactor: remove routesMap and migrate route lookups to DB#815
Ahmedhossamdev wants to merge 2 commits intomainfrom
refactor/remove-routes-map

Conversation

@Ahmedhossamdev
Copy link
Copy Markdown
Member

@Ahmedhossamdev Ahmedhossamdev commented Apr 7, 2026

Fixes: #814

Summary

  • Removes routesMap map[string]*gtfs.Route from the Manager struct
  • FindRoute() now delegates to GtfsDB.Queries.GetRoute()
  • Agency filter functions (filterTripsByAgency, filterVehiclesByAgency, filterAlertsByAgency) are now pure functions no Manager receiver, no staticMutex. A single buildRouteAgencyMap() batch-fetches route --> agency data from DB before filtering runs
  • trips_for_route_handler uses one GetRoute DB call instead of FindRoute
  • buildLookupMaps now only builds the agency map

…e queries

- Removed routesMap from Manager struct and related methods.
- Updated FindRoute to fetch routes from the database.
- Refactored filtering functions to use a routeAgencyMap for agency resolution.
- Enhanced updateFeedRealtime to build routeAgencyMap from the database.
- Simplified tests to align with the new agency filtering logic.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

Performance Smoke Test Results

Status: PASSED

Metric Value
p(95) latency 2.3 ms
Error rate 0.00%
Total requests 333
Req/sec 10.9

Smoke test config: 5 VUs x 30s. Thresholds: p(95) < 300ms, error rate < 1%.

Full results uploaded as workflow artifact: k6-smoke-summary.

Copy link
Copy Markdown
Collaborator

@fletcherw fletcherw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is on the right path, it can be simplified by inverting the filtering query (from finding agencies for routes to finding routes for agencies).

@Ahmedhossamdev Ahmedhossamdev requested a review from fletcherw April 8, 2026 10:03
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

Performance Smoke Test Results

Status: PASSED

Metric Value
p(95) latency 2.6 ms
Error rate 0.00%
Total requests 331
Req/sec 10.9

Smoke test config: 5 VUs x 30s. Thresholds: p(95) < 300ms, error rate < 1%.

Full results uploaded as workflow artifact: k6-smoke-summary.

Copy link
Copy Markdown
Collaborator

@fletcherw fletcherw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, one small nit and a rebase is all that's needed.

var trips []gtfs.Trip
var vehicles []gtfs.Vehicle
var alerts []gtfs.Alert
if tripData != nil && tripErr == nil {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: these three ifs can be merged with their corresponding if blocks on line 323, for example:

if len(agencyFilter) > 0 {
        var queries *gtfsdb.Queries
		if manager.GtfsDB != nil {
			queries = manager.GtfsDB.Queries
		}
		allowedRouteIDs := buildAllowedRouteIDs(ctx, queries, agencyFilter)

		if tripData != nil && tripErr == nil {
			tripData.Trips = filterTripsByAgency(tripData.Trips, allowedRouteIDs)
		}
       [...]

}
routeIDs := make(map[string]bool)
for agencyID := range allowed {
ids, err := queries.GetRouteIDsForAgency(ctx, agencyID)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not for this PR, but we should consider a bulk query for this.

manager.gtfsData = newStaticData
manager.GtfsDB = client
manager.agenciesMap, manager.routesMap = buildLookupMaps(newStaticData)
manager.agenciesMap = buildLookupMaps(newStaticData)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line can be totally deleted once you rebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove in-memory routesMap and migrate route lookups to database

2 participants