Skip to content

Encapsulate transit model index #5973

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

Merged

Conversation

vpaturet
Copy link
Contributor

@vpaturet vpaturet commented Jul 17, 2024

Summary

This PR encapsulates the TransitModelIndex so that it is accessed only through the TransitService/TransitEditorService interfaces.

This prepares for further refactoring steps where the mutable state that is currently stored in the TransitModelIndex, the TimetableSnapshot and the TransitLayer will be handled in a more consistent and unified way.

This also brings the code closer to the target design (immutable transit model) where all transit model updates are performed through the TransitEditorService.

Note:

  • The TransitService service should not provide direct read/write access to the underlying collections in the index. Ideally, all accessors should return an unmodifiable view of these collections. This is currently not always the case. This PR fixes this issue in a couple of accessor methods where it is easy to demonstrate that the access is indeed read-only. More accessors should be fixed in a follow-up PR.

  • The content and semantic of TransitLayer, TimetableSnapshot, TransitModelIndex are not explicit in the current design, but it appears that:

    • TransitLayer is used only in Raptor and reflects all real-time updates
    • TimetableSnapshot is used in API calls and reflects all real-time updates
    • TransitModelIndex is used in API calls and reflects scheduled data + initial state of extra journeys
      (i.e: the only updates to the index are additions of new trips, no removal/modification. Subsequent changes in added trips are not applied to the index)

Issue

No

Unit tests

Updated unit tests

Documentation

No

@vpaturet vpaturet added Technical Debt Real-Time Update The issue/PR is related to RealTime updates Skip Changelog labels Jul 17, 2024
@vpaturet vpaturet self-assigned this Jul 17, 2024
Copy link

codecov bot commented Jul 17, 2024

Codecov Report

Attention: Patch coverage is 70.96774% with 9 lines in your changes missing coverage. Please review.

Project coverage is 69.66%. Comparing base (5991d60) to head (fc53d94).
Report is 25 commits behind head on dev-2.x.

Files Patch % Lines
...ehicle_position/PollingVehiclePositionUpdater.java 0.00% 6 Missing ⚠️
...oradapter/transit/mappers/TransitLayerUpdater.java 83.33% 0 Missing and 1 partial ⚠️
...ner/standalone/configure/ConstructApplication.java 0.00% 0 Missing and 1 partial ⚠️
.../opentripplanner/transit/service/TransitModel.java 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #5973      +/-   ##
=============================================
+ Coverage      69.64%   69.66%   +0.02%     
- Complexity     17139    17165      +26     
=============================================
  Files           1937     1942       +5     
  Lines          73747    73784      +37     
  Branches        7546     7550       +4     
=============================================
+ Hits           51362    51403      +41     
  Misses         19752    19752              
+ Partials        2633     2629       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vpaturet vpaturet force-pushed the encapsulate_transit_model_index branch from 9382541 to ebb49db Compare July 17, 2024 08:47
@vpaturet vpaturet marked this pull request as ready for review July 17, 2024 09:35
@vpaturet vpaturet requested a review from a team as a code owner July 17, 2024 09:35
@leonardehrenfried
Copy link
Member

This looks like a good PR. Since it's touching a few tests, would it be possible to wait it until I managed to get #5916 through code review?

In fact this PR has had 2 approvals but because of Henrik going away and merge conflicts, it could not be merged yet. We can also decide that it has passed review even though not all requirements were met in the correct order.

@vpaturet
Copy link
Contributor Author

I will review your PR, at this stage I guess that is sufficient to get it approved and merged.

@vpaturet vpaturet force-pushed the encapsulate_transit_model_index branch from ebb49db to 7baf92b Compare July 17, 2024 13:26
@leonardehrenfried
Copy link
Member

leonardehrenfried commented Jul 19, 2024

I think treating the index as an implementation detail is a great idea and will make accessing this information a lot more sane. Nevertheless, I think we want to hear @t2gran's take on it.

abyrd
abyrd previously approved these changes Jul 23, 2024
Copy link
Member

@abyrd abyrd left a comment

Choose a reason for hiding this comment

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

The changes look good to me. Your explanation of the current role of each class, and of how this PR moves toward the target design for TransitModel seems consistent. It's noteworthy that TransitService already had most of the necessary methods, with DefaultTransitService reading through to the TransitModelIndex. In many places this PR is just using this existing publicly visible service, allowing the index to become package-private.

@leonardehrenfried leonardehrenfried requested a review from t2gran July 23, 2024 08:58
@t2gran t2gran added this to the 2.6 (next release) milestone Jul 23, 2024
Copy link
Member

@t2gran t2gran left a comment

Choose a reason for hiding this comment

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

Overall this looks ready to merge, but a few JavaDoc comments would be nice.

@vpaturet vpaturet merged commit fa60b78 into opentripplanner:dev-2.x Jul 24, 2024
5 checks passed
@vpaturet vpaturet deleted the encapsulate_transit_model_index branch July 24, 2024 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Real-Time Update The issue/PR is related to RealTime updates Skip Changelog Technical Debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants