ANIALLATOR114 / SimplyTransport

SimplyTransport - API - Website - Ingesting and presenting Transport Information
https://simplytransport.ie
Apache License 2.0
2 stars 3 forks source link

Use dict lookups #143

Closed ANIALLATOR114 closed 3 days ago

ANIALLATOR114 commented 3 days ago

Summary by Sourcery

Enhance the performance of the realtime service by replacing list iterations with dictionary lookups for more efficient data retrieval.

Enhancements:

sourcery-ai[bot] commented 3 days ago

Reviewer's Guide by Sourcery

This pull request optimizes the performance of the realtime_service.py file by replacing linear searches with dictionary lookups. The changes focus on improving the efficiency of processing realtime updates for trip schedules.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Service
    participant Dict
    Client->>Service: Request realtime schedules
    Service->>Dict: Create lookup dictionary
    Service->>Dict: Lookup trip by ID
    Dict-->>Service: Return matching trip
    Service->>Client: Return realtime schedules

File-Level Changes

Change Details Files
Optimize trip_id lookup in parse_most_recent_realtime_update function
  • Extract trip_id to a separate variable for reuse
  • Use the extracted trip_id for dictionary operations
SimplyTransport/domain/services/realtime_service.py
Improve performance in get_realtime_schedules_for_static_schedules function
  • Create a dictionary for quick lookup of most recent realtime schedules
  • Replace linear search with dictionary lookup
  • Remove unnecessary list comprehension and next() function call
SimplyTransport/domain/services/realtime_service.py

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).