Minor fixes to stop buffering#642
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts census geography spatial querying so stop-based stop_buffer lookups can be done in a single batched query while still attributing each returned geography back to the originating stop.
Changes:
- Add an internal
perStopAttributionflag to preservematch_entity_idper stop (instead of unioning stop buffers). - Update the
stop_bufferCTE generation to optionally emit one buffer per stop, enabling correct post-query grouping by stop ID. - Select
buffer.match_entity_idwhen per-stop attribution is enabled so results can be arranged per requesting stop.
Comments suppressed due to low confidence (1)
server/finders/dbfinder/census.go:92
- In the batched stop path, the SQL
LIMITis applied to the combined result set across all requested stops. WithperStopAttributionduplicating rows per intersecting stop, this can under-fetch and cause some stops to return fewer than the requestedlimit(because truncation happens before results are grouped per stop). Consider scaling the query limit bylen(entityIds)(or otherwise over-fetching) forentityType == "stop"so each stop can still receive up tolimitrows after grouping.
fields.perStopAttribution = true
var ents []*model.CensusGeography
pw := forStopids(entityIds)
if err := dbutil.Select(ctx, f.db, censusDatasetGeographySelect(limit, pw, fields), &ents); err != nil {
return nil, logErr(ctx, err)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes per-stop census geography attribution when resolving census geographies for multiple stops in a single batched query. Previously the batched stop path relied on a buffer CTE that unioned all input stops into one polygon, which lost the link back to the individual stop that matched each census tract. This adds a per-stop attribution mode so a single query can be grouped back to the correct requesting stop, while preserving the existing union behavior for routes and agencies.
Per-stop attribution in the buffer CTE
perStopAttributionflag tocensusGeographySelectFields. It is caller-driven (not GraphQL/field-selection driven) and only affects how thestop_bufferlocation filter builds its buffer CTE.match_entity_id = gtfs_stops.id, instead of unioning all stops into a single polygon. Tracts that intersect multiple input stops are intentionally duplicated so callers get per-stop apportionment.buffer.match_entity_idwhen per-stop attribution is enabled, so the result rows can be bucketed back to the originating stop.CensusGeographiesByEntityIDs grouping
entityType == "stop", setsperStopAttributionand runs one batched query for all requested stops. Grouping back to each stop is handled byarrangeGroupvia the SQL-providedmatch_entity_id, eliminating the previous loop-then-tag pass.MatchEntityIDafter scan, since the unioned buffer emits0.Test plan