Skip to content

refactor: migrate GetAgencies() from in-memory to database query#832

Merged
Ahmedhossamdev merged 3 commits intomainfrom
refactor/migrate-get-agencies-to-db
Apr 10, 2026
Merged

refactor: migrate GetAgencies() from in-memory to database query#832
Ahmedhossamdev merged 3 commits intomainfrom
refactor/migrate-get-agencies-to-db

Conversation

@Ahmedhossamdev
Copy link
Copy Markdown
Member

@Ahmedhossamdev Ahmedhossamdev commented Apr 8, 2026

Fixes: #821
Part of: #820

Summary

  • Replaces manager.gtfsData.Agencies (in-memory slice) with manager.GtfsDB.Queries.ListAgencies(ctx) in GetAgencies()
  • Updates all call sites across handler and test files to use the new DB-backed method
  • Adds mustGetAgencies test helper that wraps ListAgencies with require.NoError for cleaner test setup

Notes

  • GetAgencies() now returns []gtfsdb.Agency instead of []gtfs.Agency, so field access changes from .Id/.Language to .ID/.Lang.String etc.

…access from db queries instead of memory

- Updated tests across multiple files to replace direct access of agency ID using `Id` with `ID` for consistency.
- Introduced `mustGetAgencies` helper function to retrieve agencies in tests, ensuring that agency data is always available.
- Adjusted assertions and endpoint calls to reflect the new agency ID field naming convention.
@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 335
Req/sec 11.0

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

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

@Ahmedhossamdev Ahmedhossamdev changed the title Refactor/migrate get agencies to db refactor: migrate GetAgencies() from in-memory to database query Apr 8, 2026
@Ahmedhossamdev Ahmedhossamdev marked this pull request as ready for review April 8, 2026 15:07
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.

there's some small feedback, feel free to merge yourself after fixing, or just merge as is.

if len(stopIDs) == 0 {
// Return empty response if no stops found
agencies := utils.FilterAgencies(api.GtfsManager.GetAgencies(), agencyIDs)
agencies := utils.FilterAgencies(allAgencies, agencyIDs)
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.

this queries all agencies then filters later by IDs, we should just query by ID with a batch query in a followup.

@github-actions
Copy link
Copy Markdown

Performance Smoke Test Results

Status: PASSED

Metric Value
p(95) latency 3.2 ms
Error rate 0.00%
Total requests 329
Req/sec 10.8

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

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

@Ahmedhossamdev Ahmedhossamdev merged commit 27e8225 into main Apr 10, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace GetAgencies() with database query

2 participants