PERF: delete user and post actions vs destroy on user destroy

Users can have 100s of thousands of post and user actions, we do not want
to destroy each individually cause the tracking is enormous and the amount
of queries we would need is enormous.

This gives up on the `after_commit` hook on `post_actions` which ships a message
to clients to synchronize a post, so some phantom post_actions may remain
in the UX in the rare occasion we delete a user. The phantoms will be gone
on reload.
This commit is contained in:
Sam 2019-01-17 11:19:37 +11:00
parent 9f179d4986
commit d7c08e217a
1 changed files with 8 additions and 2 deletions

View File

@ -33,8 +33,14 @@ class User < ActiveRecord::Base
has_many :user_api_keys, dependent: :destroy
has_many :topics
has_many :user_open_ids, dependent: :destroy
has_many :user_actions, dependent: :destroy
has_many :post_actions, dependent: :destroy
# Do Not Change to user_actions/post_actions to dependent: destroy
# users can have lots of actions, bypass tracking of all destroyed objects
# this means there is a much higher likelihood that users with lots of state
# can be destroyed.
has_many :user_actions, dependent: :delete_all
has_many :post_actions, dependent: :delete_all
has_many :user_badges, -> { where('user_badges.badge_id IN (SELECT id FROM badges WHERE enabled)') }, dependent: :destroy
has_many :badges, through: :user_badges
has_many :email_logs, dependent: :delete_all