Fix duplicate service updates from STM API#96
Conversation
Co-authored-by: mmathieum <177998+mmathieum@users.noreply.github.com> Agent-Logs-Url: https://github.com/mtransitapps/commons-android/sessions/e34048c6-d065-4b3e-b0ef-828aae84c6e6
src/main/java/org/mtransit/android/commons/provider/ca/info/stm/StmInfoServiceUpdateProvider.kt
Outdated
Show resolved
Hide resolved
src/main/java/org/mtransit/android/commons/provider/ca/info/stm/StmInfoServiceUpdateProvider.kt
Show resolved
Hide resolved
Co-authored-by: mmathieum <177998+mmathieum@users.noreply.github.com> Agent-Logs-Url: https://github.com/mtransitapps/commons-android/sessions/caa1e2fd-d1b3-483b-8614-2e5bb63df628
mmathieum
left a comment
There was a problem hiding this comment.
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)
|
/gemini review |
There was a problem hiding this comment.
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.
src/main/java/org/mtransit/android/commons/provider/ca/info/stm/StmInfoServiceUpdateProvider.kt
Show resolved
Hide resolved
- 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
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 bothheaderTextsanddescriptionTexts, 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.toSet()so a language appearing in both header and description texts is only processed onceparseServiceUpdatesextracted: the alert-processing logic is moved into a dedicatedinternal fun parseServiceUpdates(etatServiceResponse, headerTimestamp, maxValidity, sourceLabel)method, making it independently testableTesting
Added
StmInfoServiceUpdateProviderTestwith unit tests covering:nullAPI response returns an empty listOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.