Skip to content

Fix duplicate service updates from STM API#96

Merged
mmathieum merged 6 commits intomasterfrom
copilot/fix-duplicate-stm-info-service-updates
Mar 21, 2026
Merged

Fix duplicate service updates from STM API#96
mmathieum merged 6 commits intomasterfrom
copilot/fix-duplicate-stm-info-service-updates

Conversation

Copy link
Contributor

Copilot AI commented Mar 21, 2026

The STM API returns multiple alerts with identical informed_entities (same route/direction/stop), causing the same service update to be displayed 2–3× for a single stop or route.

Root cause

Multiple distinct alert objects in the API response can resolve to the same (targetUUID, language) key. With no deduplication, all copies were cached and returned. Additionally, the same language key could appear in both headerTexts and descriptionTexts, causing it to be processed more than once per alert.

Fix

  • StmInfoServiceUpdateProvider: deduplicate the collected service updates by (targetUUID, language) before returning, keeping the first occurrence
  • Distinct languages: the per-alert language set is now built with .toSet() so a language appearing in both header and description texts is only processed once
  • parseServiceUpdates extracted: the alert-processing logic is moved into a dedicated internal fun parseServiceUpdates(etatServiceResponse, headerTimestamp, maxValidity, sourceLabel) method, making it independently testable

Testing

Added StmInfoServiceUpdateProviderTest with unit tests covering:

  • Duplicate alerts for the same route are deduplicated to one service update per language
  • A language present in both header and description texts is not processed twice
  • A null API response returns an empty list
  • Multiple distinct alerts for different routes each produce their own service updates
Original prompt

This section details on the original issue you should resolve

<issue_title>New stm.info API service updates > duplicates</issue_title>
<issue_description>org.mtransit.android.commons.provider.ca.info.stm.StmInfoServiceUpdateProvider

Same service updates appear multiple times.

Screenshot_20260321-024245.png

Screenshot_20260321-024222.png

Screenshot_20260321-024240.png

</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix duplicate service updates in stm.info API Fix duplicate service updates from STM API Mar 21, 2026
Copilot AI requested a review from mmathieum March 21, 2026 13:01
Copilot AI requested a review from mmathieum March 21, 2026 14:22
@mmathieum mmathieum marked this pull request as ready for review March 21, 2026 15:14
Copy link
Member

@mmathieum mmathieum left a comment

Choose a reason for hiding this comment

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

The real & primary issue was using a different agency source ID for creating and deleting the service updates (since the new provider is re-using some code from the old one)

@mmathieum
Copy link
Member

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively resolves the issue of duplicate service updates by introducing a deduplication mechanism. The core of the fix, which involves implementing equals() and hashCode() for ServiceUpdate and then using a Set to store the parsed updates, is sound. I particularly appreciate the refactoring of the parsing logic into the new, testable toServiceUpdates function. The accompanying unit tests are well-written and cover the key scenarios, ensuring the fix is robust. Overall, this is a solid improvement to the codebase.

@mmathieum mmathieum merged commit d732716 into master Mar 21, 2026
4 checks passed
@mmathieum mmathieum deleted the copilot/fix-duplicate-stm-info-service-updates branch March 21, 2026 21:03
mmathieum added a commit to mtransitapps/ca-montreal-stm-bus-android that referenced this pull request Mar 21, 2026
montransit added a commit to mtransitapps/mtransit-for-android that referenced this pull request Mar 21, 2026
montransit added a commit to mtransitapps/ca-montreal-stm-subway-android that referenced this pull request Mar 22, 2026
- commons: Enable GTFS RT Trip Updates FF mtransitapps/commons#615
- commons: CI > record screenshot > fix TZ/xmllint
- commons-android: GTFS static schedule > generate from past > use last service date to avoid missing 1st day of "generated" next schedule mtransitapps/commons-android#97
- commons-android: Increment database version for service updates
- commons-android: Fix duplicate service updates from STM API mtransitapps/commons-android#96
- commons-android: STM.info > brand new API > bump DB version
- commons-android: logs++
- commons-android: needed
- commons-android: fix debug
- commons-android: screenshot emulator time format
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.

New stm.info API service updates > duplicates

2 participants