Skip to content

Commit

Permalink
Speed up senior_delegate computation during transition to user_groups (
Browse files Browse the repository at this point in the history
…thewca#8586)

* Speed up senior_delegate computation during transition to user_groups

* Revert region_id association hack

* Add frozen_string_literal comment
  • Loading branch information
gregorbg authored Dec 2, 2023
1 parent d0f28f3 commit 50de103
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions WcaOnRails/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def two_factor_enabled?
delegate: "delegate",
senior_delegate: "senior_delegate",
}
has_many :subordinate_delegates, class_name: "User", foreign_key: "senior_delegate_id"
belongs_to :senior_delegate, -> { where(delegate_status: "senior_delegate").order(:name) }, class_name: "User", optional: true
has_many :subordinate_delegates, class_name: "User", foreign_key: "senior_delegate_id", inverse_of: :senior_delegate
belongs_to :senior_delegate, -> { where(delegate_status: "senior_delegate").order(:name) }, class_name: "User", optional: true, inverse_of: :subordinate_delegates

validate :wca_id_is_unique_or_for_dummy_account
def wca_id_is_unique_or_for_dummy_account
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddSeniorDelegateRegionIndex < ActiveRecord::Migration[7.1]
def change
add_index :users, [:region_id, :delegate_status]
end
end
3 changes: 2 additions & 1 deletion WcaOnRails/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2023_11_25_061943) do
ActiveRecord::Schema[7.1].define(version: 2023_12_02_155158) do
create_table "Competitions", id: { type: :string, limit: 32, default: "" }, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.string "name", limit: 50, default: "", null: false
t.string "cityName", limit: 50, default: "", null: false
Expand Down Expand Up @@ -1124,6 +1124,7 @@
t.string "otp_secret"
t.index ["delegate_id_to_handle_wca_id_claim"], name: "index_users_on_delegate_id_to_handle_wca_id_claim"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["region_id", "delegate_status"], name: "index_users_on_region_id_and_delegate_status"
t.index ["region_id"], name: "index_users_on_region_id"
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
t.index ["senior_delegate_id"], name: "index_users_on_senior_delegate_id"
Expand Down

0 comments on commit 50de103

Please sign in to comment.