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 network #583

Merged
merged 3 commits into from
Dec 15, 2024
Merged

remove network #583

merged 3 commits into from
Dec 15, 2024

Conversation

thatguyinabeanie
Copy link
Owner

@thatguyinabeanie thatguyinabeanie commented Dec 15, 2024

Summary by CodeRabbit

  • Chores
    • Streamlined configuration by removing the custom network setup for multiple services in the Docker Compose file.
  • New Features
    • Enhanced seeding process for accounts and tournaments, ensuring unique usernames and avoiding duplicate players.
    • Improved clarity and efficiency in the seeding logic while maintaining data integrity.

@thatguyinabeanie thatguyinabeanie enabled auto-merge (squash) December 15, 2024 21:10
Copy link

coderabbitai bot commented Dec 15, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 rubocop (1.69.1)
db/seeds.rb

There was an error parsing Gemfile: windows is not a valid platform. The available options are: [:ruby, :ruby_18, :ruby_19, :ruby_20, :ruby_21, :ruby_22, :ruby_23, :ruby_24, :ruby_25, :ruby_26, :mri, :mri_18, :mri_19, :mri_20, :mri_21, :mri_22, :mri_23, :mri_24, :mri_25, :mri_26, :rbx, :truffleruby, :jruby, :jruby_18, :jruby_19, :mswin, :mswin_18, :mswin_19, :mswin_20, :mswin_21, :mswin_22, :mswin_23, :mswin_24, :mswin_25, :mswin_26, :mswin64, :mswin64_19, :mswin64_20, :mswin64_21, :mswin64_22, :mswin64_23, :mswin64_24, :mswin64_25, :mswin64_26, :mingw, :mingw_18, :mingw_19, :mingw_20, :mingw_21, :mingw_22, :mingw_23, :mingw_24, :mingw_25, :mingw_26, :x64_mingw, :x64_mingw_20, :x64_mingw_21, :x64_mingw_22, :x64_mingw_23, :x64_mingw_24, :x64_mingw_25, :x64_mingw_26]. Bundler cannot continue.

Walkthrough

This pull request brings some neat updates to the docker-compose.yml and db/seeds.rb files. The docker-compose.yml file has had its network configuration simplified by removing the battle-stadium-network from several services, which could change how they communicate. Meanwhile, the db/seeds.rb file has been enhanced to improve the seeding logic for accounts and tournaments, ensuring unique usernames and preventing duplicate players. Overall, these changes streamline the setup and maintain clarity in the code.

Changes

File Change Summary
docker-compose.yml Removed battle-stadium-network configuration from services postgres, redis, sidekiq, backend, and backend-prod; deleted the entire networks section.
db/seeds.rb Updated seeding logic: streamlined create_tournament method, ensured unique usernames for accounts, added checks for existing players in tournaments, and nested PokemonTeam creation within player creation.

Possibly related PRs

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. This feature will be included in our Pro Plan when released.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 15, 2024
Copy link

codecov bot commented Dec 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.77%. Comparing base (705e6c2) to head (16c8efe).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #583   +/-   ##
=======================================
  Coverage   93.77%   93.77%           
=======================================
  Files          72       72           
  Lines        1736     1736           
  Branches      306      306           
=======================================
  Hits         1628     1628           
  Misses        108      108           
Flag Coverage Δ
rspec 93.77% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
db/seeds.rb (1)

Line range hint 123-141: Heads up! Let's make this player assignment more performant! 🚀

The current implementation might be a bit chatty with the database. Here are a few friendly suggestions to speed things up:

  1. The nested blocks are doing a lot of work - we could break these into separate methods for better readability
  2. We could use bulk insert operations for the pokemon teams and pokemon
  3. There's still a potential N+1 query when creating teams for each player

Here's a suggestion to make it more efficient:

def create_tournament_players(tournament, accounts, format, game, pokemon_data)
  # Build all teams first
  teams_data = accounts.map do |account|
    {
      profile_id: account.default_profile.id,
      format_id: format.id,
      game_id: game.id,
      published: true
    }
  end
  
  # Bulk insert teams
  teams = PokemonTeam.insert_all!(teams_data).index_by { |t| t['profile_id'] }
  
  # Build all players data
  players_data = accounts.map do |account|
    {
      tournament_id: tournament.id,
      account_id: account.id,
      in_game_name: account.default_profile.username,
      profile_id: account.default_profile.id,
      pokemon_team_id: teams[account.default_profile.id]['id']
    }
  end
  
  # Bulk insert players
  tournament.players.insert_all!(players_data)
  
  # Bulk insert pokemon for all teams
  pokemon_bulk_data = teams.flat_map do |_, team|
    pokemon_data.map do |pokemon|
      pokemon.merge(pokemon_team_id: team['id'])
    end
  end
  
  Pokemon.insert_all!(pokemon_bulk_data)
end

This approach should significantly reduce database calls! 🎯

🧹 Nitpick comments (2)
db/seeds.rb (2)

123-123: Hey there! Let's make this tournament creation a bit more organized! 🎮

The tournament creation logic is doing quite a bit in one go. We could make this more maintainable by breaking it into smaller, focused methods.

Here's a suggestion to split this up:

def create_tournament_phases(tournament)
  tournament.phases << create_swiss_phase(tournament)
  tournament.phases << create_top_cut_phase(tournament)
end

def create_swiss_phase(tournament)
  Phases::Swiss.create!(
    name: "#{tournament.name} - Swiss Rounds",
    tournament: tournament,
    number_of_rounds: 5,
    order: 0
  )
end

def create_top_cut_phase(tournament)
  Phases::SingleEliminationBracket.create!(
    name: "#{tournament.name} - Top Cut!",
    tournament: tournament,
    order: 1
  )
end

Line range hint 127-129: Quick suggestion about the pokemon_data validation! 🔍

The validation check for pokemon_data could be moved to the beginning of the method to fail fast before we do any database operations. This would save us some processing time if the data is invalid!

Something like this:

def validate_pokemon_data(pokemon_data)
  raise "Invalid pokemon data" unless pokemon_data.all? { |p| p[:species].present? && p[:position].present? }
end

# Call this at the start of the method
validate_pokemon_data(pokemon_data)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 184b9a7 and 16c8efe.

📒 Files selected for processing (2)
  • db/seeds.rb (1 hunks)
  • docker-compose.yml (0 hunks)
💤 Files with no reviewable changes (1)
  • docker-compose.yml

@thatguyinabeanie thatguyinabeanie merged commit b91d065 into main Dec 15, 2024
18 checks passed
@thatguyinabeanie thatguyinabeanie deleted the remove-network branch December 15, 2024 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant