Skip to content

Commit

Permalink
Merge pull request #2102 from MushroomObserver/user-remove-bonuses-co…
Browse files Browse the repository at this point in the history
…lumn

Clean up after `UserStats`: Remove `User.bonuses`
  • Loading branch information
nimmolo committed Apr 16, 2024
2 parents 8a72ef7 + 9a85d8a commit 3c8a36a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
12 changes: 0 additions & 12 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
# email:: Email address.
# admin:: Allowed to enter admin mode?
# alert:: Alert message we need to display for User. (serialized)
# bonuses:: List of zero or more contribution bonuses. (serialized)
# contribution:: Contribution score (integer).
#
# ==== Profile
Expand Down Expand Up @@ -155,7 +154,6 @@
#
# ==== Profile
# percent_complete:: How much of profile has User finished?
# sum_bonuses:: Add up all the bonuses User has earned.
#
# ==== Object ownership
# comments:: Comment's they've posted.
Expand Down Expand Up @@ -726,16 +724,6 @@ def percent_complete
result * 100 / max
end

# Sum up all the bonuses the User has earned.
#
# contribution += user.sum_bonuses
#
def sum_bonuses
return nil unless bonuses

bonuses.inject(0) { |acc, elem| acc + elem[0] }
end

def successful_contributor?
observations.any?
end
Expand Down
6 changes: 2 additions & 4 deletions app/models/user_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,10 @@ def refresh_all_user_stats(dry_run: false)

# This runs after the migration, to copy columns from users to user_stats
# It's a batch insert, so it's fast.
# TODO: After the initial population, drop the column `bonuses` from User,
# and remove references to bonuses in `pluck` and the hash here.
def create_user_stats_for_all_users_without
records = User.where.missing(:user_stats).
pluck(:id, :bonuses).map do |id, bonuses|
{ user_id: id, bonuses: bonuses }
pluck(:id).map do |id|
{ user_id: id }
end

UserStats.insert_all(records)
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240416050340_users_remove_bonuses_column.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class UsersRemoveBonusesColumn < ActiveRecord::Migration[7.1]
def change
remove_column :users, :bonuses
end
end
3 changes: 1 addition & 2 deletions 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: 2024_04_15_115711) do
ActiveRecord::Schema[7.1].define(version: 2024_04_16_050340) do
create_table "api_keys", id: :integer, charset: "utf8mb3", force: :cascade do |t|
t.datetime "created_at", precision: nil
t.datetime "last_used", precision: nil
Expand Down Expand Up @@ -708,7 +708,6 @@
t.integer "location_id"
t.integer "image_id"
t.string "locale", limit: 5
t.text "bonuses"
t.boolean "email_comments_owner", default: true, null: false
t.boolean "email_comments_response", default: true, null: false
t.boolean "email_comments_all", default: false, null: false
Expand Down

0 comments on commit 3c8a36a

Please sign in to comment.