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

feat: OverFast API v3 #208

Merged
merged 9 commits into from
Nov 3, 2024
Merged

feat: OverFast API v3 #208

merged 9 commits into from
Nov 3, 2024

Conversation

TeKrop
Copy link
Owner

@TeKrop TeKrop commented Nov 3, 2024

Summary by Sourcery

Implement OverFast API v3 with a new Player Cache system to optimize data retrieval and reduce external calls. Refactor existing parsers and cache management to improve performance and maintainability. Update documentation and tests to align with the new architecture.

New Features:

  • Introduce Player Cache to store HTML and search data for players, reducing calls to Blizzard servers when player data hasn't changed.

Enhancements:

  • Refactor cache management to use Player Cache instead of Parser Cache, improving efficiency and reducing unnecessary data refreshes.
  • Update rate limit settings to allow more requests per second and increase burst capacity, enhancing API performance.

Documentation:

  • Update README to reflect changes in caching strategy and architecture, including the introduction of Player Cache and updated rate limits.

Tests:

  • Add comprehensive tests for new Player Cache functionality and refactored parsers, ensuring robust data handling and caching.

@TeKrop TeKrop added the enhancement New feature or request label Nov 3, 2024
@TeKrop TeKrop self-assigned this Nov 3, 2024
Copy link
Contributor

sourcery-ai bot commented Nov 3, 2024

Reviewer's Guide by Sourcery

This pull request implements version 3 of the OverFast API, featuring a major architectural overhaul. The changes include a reorganization of the codebase into domain-driven modules, improvements to the caching system, and refinements to the API response handling. The update focuses on better code organization, improved performance, and enhanced maintainability.

Sequence diagram for default API request handling

sequenceDiagram
    autonumber
    actor User
    participant Nginx
    participant Redis
    participant App
    participant Blizzard
    User->>+Nginx: Make an API request
    Nginx->>+Redis: Make an API Cache request
    alt API Cache is available
        Redis-->>Nginx: Return API Cache data
        Nginx-->>User: Return API Cache data
    else
        Redis-->>-Nginx: Return no result
        Nginx->>+App: Transmit the request to App server
        App->>+Blizzard: Retrieve data
        Blizzard-->>-App: Return data
        App->>App: Parse HTML page
        App->>Redis: Store data into API Cache
        App-->>-Nginx: Return API data
        Nginx-->>-User: Return API data
    end
Loading

Sequence diagram for player profile request handling

sequenceDiagram
    autonumber
    actor User
    participant Nginx
    participant Redis
    participant App
    participant Blizzard
    User->>+Nginx: Make an API request
    Nginx->>+Redis: Make an API Cache request
    alt API Cache is available
        Redis-->>Nginx: Return API Cache data
        Nginx-->>User: Return API Cache data
    else
        Redis-->>-Nginx: Return no result
        Nginx->>+App: Transmit the request to App server
        App->>+Blizzard: Make a Player Search request
        Blizzard-->>-App: Return Player Search data
        App->>+Redis: Make Player Cache request
        alt Player Cache is available and up-to-date
            Redis-->>App: Return Player Cache
            App->>App: Parse HTML page
        else
            Redis-->>-App: Return no result
            App->>+Blizzard: Retrieve Player data (HTML)
            Blizzard-->>-App: Return Player data
            App->>App: Parse HTML page
            App->>Redis: Store data into Player Cache
        end
        App->>Redis: Store data into API Cache
        App-->>-Nginx: Return API data
        Nginx-->>-User: Return API data
    end
Loading

Updated class diagram for CacheManager

classDiagram
    class CacheManager {
        +redis_server
        +log_warning(err: RedisError) void
        +get_cache_key_from_request(request: Request) str
        +__compress_json_value(value: dict|list) str
        +__decompress_json_value(value: str) dict|list
        +redis_connection_handler(func: Callable)
        +get_api_cache(cache_key: str) str|None
        +get_player_cache(player_id: str) dict|list|None
        +update_api_cache(cache_key: str, value: dict|list, expire: int) void
        +update_player_cache(player_id: str, value: dict) void
        +get_search_data_cache(data_type: SearchDataType, cache_key: str) str|None
        +update_search_data_cache(data_type: SearchDataType, cache_key: str, value: str) void
        +is_being_rate_limited() bool
    }
Loading

Updated class diagram for PlayerCareerParser

classDiagram
    class PlayerCareerParser {
        +root_path
        +valid_http_codes
        +filter_request_using_query(kwargs: dict) dict
        +__get_summary() dict
        +__get_namecard_url() str|None
        +__get_last_updated_at_value() int|None
        +__get_title(profile_div: Tag) str|None
    }
Loading

File-Level Changes

Change Details Files
Reorganized project structure into domain-driven modules
  • Split code into domain-specific modules (heroes, players, roles, etc.)
  • Moved related models, enums, and parsers into their respective domain modules
  • Renamed handlers to controllers for better semantic clarity
  • Created dedicated exceptions for each domain
app/heroes/*
app/players/*
app/roles/*
app/gamemodes/*
app/maps/*
Revamped caching system architecture
  • Replaced Parser Cache with Player Cache for better data management
  • Removed background cache refresh system in favor of on-demand updates
  • Implemented cache timeout reset on access for player data
  • Simplified Redis connection handling
app/cache_manager.py
app/config.py
Enhanced API response and error handling
  • Removed validation_error_handler decorator in favor of global exception handler
  • Improved error messages and logging
  • Added human-readable cache timeout information to API documentation
  • Standardized response models across endpoints
app/main.py
app/decorators.py
app/helpers.py
Improved testing infrastructure
  • Reorganized test fixtures to match new module structure
  • Added dedicated test helpers module
  • Enhanced mock implementations for better test coverage
  • Updated test configurations for new architecture
tests/*
pyproject.toml
conftest.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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard 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

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @TeKrop - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider splitting such large refactoring PRs into smaller, focused changes in the future to make review easier - while this one is well structured, smaller PRs reduce risk and cognitive load
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 1 issue found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

README.md Outdated Show resolved Hide resolved
tests/test_cache_manager.py Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Nov 3, 2024

@TeKrop TeKrop merged commit 7d24e14 into main Nov 3, 2024
3 checks passed
@TeKrop TeKrop deleted the feature/overfast-api-v3 branch November 3, 2024 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant