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: optimized performances on player profiles parsing #210

Merged
merged 1 commit into from
Nov 5, 2024

Conversation

TeKrop
Copy link
Owner

@TeKrop TeKrop commented Nov 5, 2024

Summary by Sourcery

Optimize player profile parsing by using initialized filters and introduce a profiling feature with pyinstrument for debugging.

New Features:

  • Introduce a profiling feature using pyinstrument, which can be enabled via settings for debugging purposes.

Enhancements:

  • Optimize player profile parsing by initializing filters in the constructor and using them throughout the parsing process.

Build:

  • Add pyinstrument as a development dependency in pyproject.toml.

Tests:

  • Update tests to initialize filters before parsing player career data.

Before

image

After

image

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

sourcery-ai bot commented Nov 5, 2024

Reviewer's Guide by Sourcery

This PR implements performance optimizations for player profiles parsing by reducing unnecessary HTML parsing, introducing filters caching, and optimizing BeautifulSoup queries. The changes also add request profiling capabilities for debugging purposes.

Updated class diagram for PlayerCareerParser

classDiagram
    class PlayerCareerParser {
        +dict filters
        +__init__(**kwargs)
        +_init_filters(**kwargs)
        +filter_request_using_query(**_)
        +_filter_stats()
        +_filter_all_stats_data()
        +parse_data()
        +__get_summary()
        +get_stats()
        +__get_platform_stats(platform, platform_class)
        +__get_gamemode_infos(statistics_section, gamemode)
        +__get_heroes_comparisons(top_heroes_section)
        +__get_career_stats(career_stats_section)
    }
    class BasePlayerParser {
        <<abstract>>
    }
    PlayerCareerParser --|> BasePlayerParser
Loading

Updated class diagram for PlayerCareerStatsParser

classDiagram
    class PlayerCareerStatsParser {
        +filter_request_using_query(**_)
        +parse_data()
    }
    class PlayerCareerParser {
        <<abstract>>
    }
    PlayerCareerStatsParser --|> PlayerCareerParser
Loading

File-Level Changes

Change Details Files
Optimized BeautifulSoup parsing and queries
  • Added SoupStrainer to parse only the main content section
  • Replaced select_one() calls with more efficient find()
  • Optimized HTML traversal by using direct children access instead of find_all()
  • Simplified text extraction by using .string instead of .get_text()
app/parsers.py
app/players/parsers/player_career_parser.py
Implemented filter caching in PlayerCareerParser
  • Added filters as class variable to store query parameters
  • Moved filter initialization to init method
  • Removed redundant parameter passing between methods
app/players/parsers/player_career_parser.py
app/players/parsers/player_career_stats_parser.py
Added request profiling capabilities
  • Implemented profiling middleware using pyinstrument
  • Added profiling configuration option
  • Profile requests can be triggered using profile=true query parameter
app/main.py
app/config.py
.env.dist

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 and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟡 Security: 1 issue found
  • 🟡 Testing: 1 issue found
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

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.

app/main.py Show resolved Hide resolved
app/players/parsers/player_career_parser.py Show resolved Hide resolved
app/players/parsers/player_career_parser.py Show resolved Hide resolved
app/players/parsers/player_career_parser.py Show resolved Hide resolved
@TeKrop TeKrop force-pushed the feature/player-profiles-perf branch from a3e5de2 to 32d8e71 Compare November 5, 2024 07:39
Copy link

sonarcloud bot commented Nov 5, 2024

@TeKrop TeKrop merged commit 9a602d0 into main Nov 5, 2024
3 checks passed
@TeKrop TeKrop deleted the feature/player-profiles-perf branch November 5, 2024 07:50
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