PERF: use delete_all to remove notifications and topic_users

PERF: use delete_all to remove notifications and topic_users

Previously we used destroy here which could be extremely expensive

diff --git a/app/models/user.rb b/app/models/user.rb
index f26ac53..0b11dfe 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -22,8 +22,8 @@ class User < ActiveRecord::Base
   include HasDestroyedWebHook
 
   has_many :posts
-  has_many :notifications, dependent: :destroy
-  has_many :topic_users, dependent: :destroy
+  has_many :notifications, dependent: :delete_all
+  has_many :topic_users, dependent: :delete_all
   has_many :category_users, dependent: :destroy
   has_many :tag_users, dependent: :destroy
   has_many :user_api_keys, dependent: :destroy

GitHub sha: 26b4dbde

1 Like

delete_all skips callbacks and notifications have a callback that refreshes the notification count.

This does not matter, the user is being nuked :slight_smile:

O I should have read what the method does first. Apologies :grinning:

2 Likes