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(predictions): only fetch predictions for a train when user opens the train opover #203

Merged
merged 8 commits into from
May 22, 2024

Conversation

rudiejd
Copy link
Contributor

@rudiejd rudiejd commented May 21, 2024

Motivation

Currently, we fetch departure predictions for every train every time the page is loaded. This is making the NTT slow, and leading to our hitting V3 API limits.

Changes

Only call the prediction API when the user opens the popover for a train

Another way to do this might be to call for predictions on a per-line basis, store them in the useMbtaApi hook, and then match them up with vehicles. However, this would mean the predictions only get updated whenever the train positions are updated.

Testing Instructions

Run the app locally and verify that the prediction API is not called until you open the pop-over for a vehicle.

@github-actions github-actions bot added frontend Change to frontend code backend Change to backend code labels May 21, 2024
return None
return {'departure_time': prediction[0]['departure_time']}
except Exception as e:
print(f"Error getting predictions for trip: {e}")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the error handling could probably be a bit better here lol

@rudiejd rudiejd changed the title Fix/prediction fetching fix(predictions): only fetch predictions for a train when user opens the train opover May 21, 2024
@devinmatte devinmatte merged commit c564321 into main May 22, 2024
3 checks passed
@devinmatte devinmatte deleted the fix/prediction-fetching branch May 22, 2024 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Change to backend code frontend Change to frontend code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants