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

Remove unused Siri code #5893

Merged
merged 1 commit into from
Jun 11, 2024

Conversation

leonardehrenfried
Copy link
Member

@leonardehrenfried leonardehrenfried commented Jun 6, 2024

Summary

While I was investigating how to handle cancellations for Siri and GTFS (for later unification) I stumbled over a peculiar piece of complicated logic that appears to be completely unused: keeping the pattern -> stop relationship of realtime-added patterns in SiriTripPatternCache.

It seems that once upon a time the API was directly requesting some information from the cache but the method getAddedTripPatternsForStop is now completely unused.

I believe that it can be removed.

The best way to review this, would be to look at the code yourself and start removing the dead code to see what else can also be removed.

Issue

#4816

@leonardehrenfried leonardehrenfried requested a review from a team as a code owner June 6, 2024 10:20
@leonardehrenfried leonardehrenfried added Technical Debt Real-Time Update The issue/PR is related to RealTime updates Skip Changelog labels Jun 6, 2024
Copy link

codecov bot commented Jun 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.64%. Comparing base (0a58d0f) to head (bd35ec5).
Report is 1 commits behind head on dev-2.x.

Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #5893      +/-   ##
=============================================
+ Coverage      68.62%   68.64%   +0.02%     
+ Complexity     16824    16821       -3     
=============================================
  Files           1927     1927              
  Lines          72929    72878      -51     
  Branches        7475     7469       -6     
=============================================
- Hits           50044    50028      -16     
+ Misses         20312    20277      -35     
  Partials        2573     2573              

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

@leonardehrenfried leonardehrenfried changed the title Clean out Siri code Remove unused Siri code Jun 6, 2024
@leonardehrenfried leonardehrenfried assigned abyrd and unassigned abyrd Jun 6, 2024
@t2gran t2gran added this to the 2.6 (next release) milestone Jun 7, 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.

I began review by removing the method getAddedTripPatternsForStop which is clearly unused. With that method removed, the field patternsForStop is solely accessed by SiriTripPatternCache#getOrCreateTripPattern. The same is true for the field updatedTripPatternsForTripCache. Both of these fields are removed by this PR.

The only remaining accesses to either of these fields were in method getOrCreateTripPattern, from lines 167 to 195 (the same large block of code removed in this PR).

The question is then whether the Map operations in this code block existed solely to maintain information whose only escape path was the unused getAddedTripPatternsForStop method, or if they have side effects on the details of shared objects (specifically the TripPattern Map values) which remain visible by other reference chains and methods.

Reviewing that code block, it looks like the only operations performed on the TripPatterns is adding or removing them from the Maps. The rest of the code is just for logging these actions. The long block comment before this code seems to describe its purpose and confirm that it only adds or removes the instance as a whole to indexes.

So it does appear that all this code can be removed without any impact on the rest of the system, which also brings this SiriTripPatternCache closer to the non-Siri/GTFS version.

@abyrd
Copy link
Member

abyrd commented Jun 11, 2024

Altough git shows me as the last author of the long block comment in the code changed by this PR, this is only due to some recent reformatting. I did not write that comment, so needed to interpret it myself while reviewing. A few words and ideas were unclear to me. I'll summarize in case it helps later improve other documentation.

The first term I didn't understand is "departureRow searches", which are apparently the original purpose of the indexes and methods being removed. An explanation is found at GraphQLDataFetchers.GraphQLDepartureRow, but that comment is still difficult to understand for someone not already familiar with the subject. A departure row is said to be a "combination of a pattern and a stop of that pattern", but it's not clear what it means that they are combined. I suppose this means something like a compound key, representing a particular stop on a particular pattern. The next line says "they are de-duplicated so for each pattern there will only be a single departure row." This probably isn't correct - there must be more than one departure row per pattern. I'd guess there are the same number of departure rows as there are stops on a given pattern. The comment might mean that the departure rows have semantic equality, so a departure row with a given stop ID will only appear once within a given pattern. So maybe: "departure rows are de-duplicated, such that for each pattern there is only be a single departure row per stop on the pattern".

Second, the use of the word "cache" throughout the realtime code always sows some uncertainty when I'm reading it. I am not sure whether there's a true intent or design for these Maps to serve as "caches" for object instances, rather than just indexes or views of information organized differently in other fields. The comments seem to be using the verb "cache" as a synonym for "to record" or "to index", without the conventional emphasis on semantic deduplication and reuse of instances.

@vpaturet
Copy link
Contributor

vpaturet commented Jun 11, 2024

Same conclusion for me, this code is not in use anymore and does not have any side-effect besides logging.

@leonardehrenfried leonardehrenfried merged commit 7dc5828 into opentripplanner:dev-2.x Jun 11, 2024
5 checks passed
@leonardehrenfried leonardehrenfried deleted the clean-out-siri branch June 11, 2024 13:27
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