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

add indexes for db performance #557

Merged
merged 25 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/spellcheck.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: 'Check spelling'
on: # rebuild any PRs and main branch changes
pull_request:

jobs:
spellcheck: # run the action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: streetsidesoftware/cspell-action@v6
18 changes: 9 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ruby "3.3.5"

# Rails framework
gem "active_model_serializers", "~> 0"
gem "bootsnap", ">= 1.4.4", require: false
gem "bootsnap", ">= 1", require: false
gem "rails", "~> 7.2"
gem "sprockets-rails"
gem "stimulus-rails", "~> 1"
Expand All @@ -20,10 +20,10 @@ gem "pundit"
gem "friendly_id"
gem "kaminari"
gem "kredis", "~> 1"
gem "pg", "~> 1.5.7"
gem "pg", "~> 1"

# API and Serialization
gem "json", "~> 2.7"
gem "json", "~> 2"
gem "jsonapi-serializer", "~> 2"
gem "rswag-api"
gem "rswag-ui"
Expand All @@ -33,19 +33,19 @@ gem "versionist", "~> 2"
gem "sidekiq", "~> 7"

# Security
gem "openssl", "~> 3.2"
gem "openssl", "~> 3"
gem "rack-attack", "~> 6"
gem "rack-cors", "~> 2"

# Utilities
gem "awesome_print"
gem "dotenv-rails"
gem "ostruct", "~> 0"
gem "parallel", "~> 1.26"
gem "parallel", "~> 1"
gem "retries"
gem "svix"
gem "typhoeus", "~> 1.4"
gem "uri", "~> 0.13.1"
gem "typhoeus", "~> 1"
gem "uri", "~> 1"

# Redis
gem "redis", "~> 5"
Expand All @@ -61,7 +61,7 @@ gem "traceroute", "~> 0"
gem "tzinfo-data", platforms: %i[windows jruby]

# Web Server
gem "puma", "~> 6.4"
gem "puma", "~> 6"

group :development do
gem "rails-erd"
Expand Down Expand Up @@ -91,7 +91,7 @@ group :development, :test do
gem "parallel_tests", "~> 4"
gem "rspec-json_expectations"
gem "rspec-rails"
gem "ruby-lsp-rails", "~> 0.3.15"
gem "ruby-lsp-rails", "~> 0.3"
gem "ruby-lsp-rspec"
gem "spring", "~> 4"
gem "webmock", "~> 3"
Expand Down
34 changes: 17 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ GEM
net-smtp
marcel (1.0.4)
mini_mime (1.1.5)
minitest (5.25.1)
minitest (5.25.2)
msgpack (1.7.5)
net-imap (0.5.1)
date
Expand Down Expand Up @@ -229,7 +229,7 @@ GEM
psych (5.2.0)
stringio
public_suffix (6.0.1)
puma (6.4.3)
puma (6.5.0)
nio4r (~> 2.0)
pundit (2.4.0)
activesupport (>= 3.0.0)
Expand Down Expand Up @@ -351,16 +351,16 @@ GEM
rswag-ui (2.16.0)
actionpack (>= 5.2, < 8.1)
railties (>= 5.2, < 8.1)
rubocop (1.68.0)
rubocop (1.69.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
rubocop-ast (>= 1.32.2, < 2.0)
rubocop-ast (>= 1.36.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.36.1)
parser (>= 3.3.1.0)
rubocop-checkstyle_formatter (0.6.0)
Expand Down Expand Up @@ -433,7 +433,7 @@ GEM
bundler-audit (~> 0.9.0)
rubyzip (2.3.2)
securerandom (0.3.2)
selenium-webdriver (4.26.0)
selenium-webdriver (4.27.0)
base64 (~> 0.2)
logger (~> 1.4)
rexml (~> 3.2, >= 3.2.5)
Expand Down Expand Up @@ -461,7 +461,7 @@ GEM
simplecov-lcov (0.8.0)
simplecov_json_formatter (0.1.4)
smart_properties (1.17.0)
sorbet-runtime (0.5.11647)
sorbet-runtime (0.5.11668)
spring (4.2.1)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -489,7 +489,7 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.6.0)
uri (0.13.1)
uri (1.0.2)
useragent (0.16.10)
versionist (2.0.1)
activesupport (>= 3)
Expand Down Expand Up @@ -531,26 +531,26 @@ DEPENDENCIES
active_model_serializers (~> 0)
awesome_print
bcrypt (~> 3)
bootsnap (>= 1.4.4)
bootsnap (>= 1)
brakeman (~> 6)
bundler-audit (~> 0)
debug (~> 1)
dotenv-rails
factory_bot_rails (~> 6)
faker (~> 3)
friendly_id
json (~> 2.7)
json (~> 2)
jsonapi-serializer (~> 2)
jwt (~> 2.8)
kaminari
kredis (~> 1)
listen (~> 3.3)
openssl (~> 3.2)
openssl (~> 3)
ostruct (~> 0)
parallel (~> 1.26)
parallel (~> 1)
parallel_tests (~> 4)
pg (~> 1.5.7)
puma (~> 6.4)
pg (~> 1)
puma (~> 6)
pundit
rack-attack (~> 6)
rack-cors (~> 2)
Expand Down Expand Up @@ -589,7 +589,7 @@ DEPENDENCIES
rubocop-shopify
rubocop-thread_safety
ruby-lsp
ruby-lsp-rails (~> 0.3.15)
ruby-lsp-rails (~> 0.3)
ruby-lsp-rspec
ruby_audit (~> 2)
selenium-webdriver (~> 4)
Expand All @@ -606,9 +606,9 @@ DEPENDENCIES
timecop (~> 0)
traceroute (~> 0)
turbo-rails (~> 2)
typhoeus (~> 1.4)
typhoeus (~> 1)
tzinfo-data
uri (~> 0.13.1)
uri (~> 1)
versionist (~> 2)
web-console (~> 4)
webmock (~> 3)
Expand Down
19 changes: 19 additions & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: "0.2"
ignorePaths:
- db/schema.rb
- Gemfile
- Gemfile.lock
dictionaryDefinitions: []
dictionaries:
- en_US
- companies
- softwareTerms
- misc
- ruby
- rails
- bash
- typescript
- node
words:
ignoreWords: []
import: []
74 changes: 74 additions & 0 deletions db/migrate/20241126212912_add_indexes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class AddIndexes < ActiveRecord::Migration[7.2]
def change
# Accounts table
add_index :accounts, :archived_at # If querying for active/archived accounts
add_index :accounts, :default_profile_id, unique: true
add_index :accounts, :created_at

# Clerk Users table
add_index :clerk_users, [:account_id, :clerk_user_id], unique: true

# Organizations table
add_index :organizations, :partner # For filtering partner orgs

# Tournaments table
remove_index :tournaments, :current_phase_id
remove_index :tournaments, :game_id
remove_index :tournaments, :format_id
remove_index :tournaments, :organization_id
add_index :tournaments, :published # For filtering published tournaments
add_index :tournaments, [:organization_id, :start_at] # For org's upcoming tournaments
add_index :tournaments, :start_at # For finding upcoming tournaments
add_index :tournaments, [:game_id, :start_at] # For game-specific tournament listings
add_index :tournaments, [:format_id, :start_at] # For format-specific tournament listings

# Players table
add_index :players, :checked_in_at # For tournament check-in queries
add_index :players, [:tournament_id, :team_sheet_submitted]
add_index :players, [:tournament_id, :checked_in_at] # For checking tournament status
add_index :players, [:tournament_id, :round_wins] # For tournament standings
add_index :players, [:tournament_id, :dropped] # For active players in tournament
add_index :players, [:tournament_id, :disqualified] # For DQ status checks
add_index :players, [:profile_id, :created_at] # For player history
add_index :players, [:account_id, :created_at] # For player history

# Pokemon Teams table
add_index :pokemon_teams, [:profile_id, :archived_at] # For active teams by profile
add_index :pokemon_teams, [:format_id, :created_at] # For recent teams by format
add_index :pokemon_teams, [:game_id, :format_id, :created_at]
remove_index :pokemon_teams, :format_id
remove_index :pokemon_teams, :game_id


# Pokemon table
add_index :pokemon, :species # For species-based searches
add_index :pokemon, [:pokemon_team_id, :species] # For team composition analysis
remove_index :pokemon, :pokemon_team_id

# Phases table
remove_index :phases, :current_round_id
remove_index :phases, :tournament_id
add_index :phases, [:tournament_id, :order]

# Phase Players
remove_index :phase_players, [:phase_type, :phase_id]
remove_index :phase_players, :player_id
add_index :phase_players, [:phase_id, :player_id]


# Rounds table
remove_index :rounds, [:phase_id, :round_number]
remove_index :rounds, :phase_id

# Matches table
add_index :matches, [:tournament_id, :created_at] # For tournament match history
add_index :matches, [:tournament_id, :phase_id, :round_id, :table_number]
remove_index :matches, :tournament_id
remove_index :matches, [:round_id, :player_one_id, :player_two_id]

# Chat Messages table
add_index :chat_messages, [:match_id, :account_id, :sent_at] # For message history
add_index :chat_messages, [:match_id, :profile_id, :sent_at] # For message history

end
end
Loading
Loading