Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(subscribeToPredictions): ensure old data present when merging in new data #596

Merged
merged 6 commits into from
Dec 18, 2024

Conversation

KaylaBrady
Copy link
Collaborator

Summary

Ticket: 🤖 | Nearby | Predictions unavailable more than expected

What is this PR for?
Nearby Transit was getting stuck showing "Predictions Unavailable" For routes that had predictions, such as RL. Predictions reliably loaded in Stop Details, but not in Nearby Transit.

After adding debug logs, it seems the issue is that where we merge new predictions messages with the current state of predictions, the current state of predictions is out of date & often null, so we lose predictions from earlier messages. The docs for LiveData.getValue() mention

Note that calling this method on a background thread does not guarantee that the latest value set will be received.

Whereas StateFlow:

always has a value which can be safely read at any time.

iOS

  • If you added any user-facing strings on iOS, are they included in Localizable.xcstrings?
    • Add temporary machine translations, marked "Needs Review"
      android
  • All user-facing strings added to strings resource

Testing

What testing have you done?

  • Ran locally, confirmed predictions reliably load in nearby transit

@KaylaBrady KaylaBrady requested a review from a team as a code owner December 18, 2024 17:19
@KaylaBrady KaylaBrady requested a review from BrandonTR December 18, 2024 17:19

val predictions: StateFlow<PredictionsByStopJoinResponse?> = _predictions
val predictionsFlow =
predictions.map { it?.toPredictionsStreamDataResponse() }.debounce(0.1.seconds)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the ordering of map vs. debounce relevant?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh good point, I'll swap to the two to avoid excessive maps

Copy link
Contributor

@JackVCurtis JackVCurtis left a comment

Choose a reason for hiding this comment

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

👍

@@ -61,7 +63,7 @@ fun subscribeToAlerts(
val viewModel: AlertsViewModel = viewModel(factory = AlertsViewModel.Factory(alertsRepository))

LifecycleResumeEffect(key1 = null) {
viewModel.connect()
CoroutineScope(Dispatchers.IO).launch { viewModel.connect() }
Copy link
Collaborator Author

@KaylaBrady KaylaBrady Dec 18, 2024

Choose a reason for hiding this comment

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

@JackVCurtis added the use of Dipsatchers.IO in #557, and I mistakenly removed in #588.

This addresses some of the jankiness / lag while panning the map or scrolling the list of departures.

Applying across all channels.

Copy link
Contributor

@JackVCurtis JackVCurtis 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!

@KaylaBrady KaylaBrady merged commit 1c94685 into main Dec 18, 2024
5 checks passed
@KaylaBrady KaylaBrady deleted the kb-predictions-fix branch December 18, 2024 19:33
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.

2 participants