@@ -50,6 +50,7 @@ class Account < ApplicationRecord
5050 USERNAME_RE = /[a-z0-9_]+([a-z0-9_\. -]+[a-z0-9_]+)?/i
5151 MENTION_RE = /(?<=^|[^\/ [:word:]])@((#{ USERNAME_RE } )(?:@[a-z0-9\. \- ]+[a-z0-9]+)?)/i
5252
53+ include AccountAssociations
5354 include AccountAvatar
5455 include AccountFinderConcern
5556 include AccountHeader
@@ -60,9 +61,6 @@ class Account < ApplicationRecord
6061
6162 enum protocol : [ :ostatus , :activitypub ]
6263
63- # Local users
64- has_one :user , inverse_of : :account
65-
6664 validates :username , presence : true
6765
6866 # Remote user validations
@@ -77,45 +75,6 @@ class Account < ApplicationRecord
7775 validates :note , length : { maximum : 160 } , if : -> { local? && will_save_change_to_note? }
7876 validates :fields , length : { maximum : 4 } , if : -> { local? && will_save_change_to_fields? }
7977
80- # Timelines
81- has_many :stream_entries , inverse_of : :account , dependent : :destroy
82- has_many :statuses , inverse_of : :account , dependent : :destroy
83- has_many :favourites , inverse_of : :account , dependent : :destroy
84- has_many :mentions , inverse_of : :account , dependent : :destroy
85- has_many :notifications , inverse_of : :account , dependent : :destroy
86-
87- # Pinned statuses
88- has_many :status_pins , inverse_of : :account , dependent : :destroy
89- has_many :pinned_statuses , -> { reorder ( 'status_pins.created_at DESC' ) } , through : :status_pins , class_name : 'Status' , source : :status
90-
91- # Endorsements
92- has_many :account_pins , inverse_of : :account , dependent : :destroy
93- has_many :endorsed_accounts , through : :account_pins , class_name : 'Account' , source : :target_account
94-
95- # Media
96- has_many :media_attachments , dependent : :destroy
97-
98- # PuSH subscriptions
99- has_many :subscriptions , dependent : :destroy
100-
101- # Report relationships
102- has_many :reports
103- has_many :targeted_reports , class_name : 'Report' , foreign_key : :target_account_id
104-
105- has_many :report_notes , dependent : :destroy
106- has_many :custom_filters , inverse_of : :account , dependent : :destroy
107-
108- # Moderation notes
109- has_many :account_moderation_notes , dependent : :destroy
110- has_many :targeted_moderation_notes , class_name : 'AccountModerationNote' , foreign_key : :target_account_id , dependent : :destroy
111-
112- # Lists
113- has_many :list_accounts , inverse_of : :account , dependent : :destroy
114- has_many :lists , through : :list_accounts
115-
116- # Account migrations
117- belongs_to :moved_to_account , class_name : 'Account' , optional : true
118-
11978 scope :remote , -> { where . not ( domain : nil ) }
12079 scope :local , -> { where ( domain : nil ) }
12180 scope :expiring , -> ( time ) { remote . where . not ( subscription_expires_at : nil ) . where ( 'subscription_expires_at < ?' , time ) }
@@ -453,6 +412,7 @@ def emojis
453412 before_create :generate_keys
454413 before_validation :normalize_domain
455414 before_validation :prepare_contents , if : :local?
415+ before_destroy :clean_feed_manager
456416
457417 private
458418
@@ -478,4 +438,19 @@ def normalize_domain
478438 def emojifiable_text
479439 [ note , display_name , fields . map ( &:value ) ] . join ( ' ' )
480440 end
441+
442+ def clean_feed_manager
443+ reblog_key = FeedManager . instance . key ( :home , id , 'reblogs' )
444+ reblogged_id_set = Redis . current . zrange ( reblog_key , 0 , -1 )
445+
446+ Redis . current . pipelined do
447+ Redis . current . del ( FeedManager . instance . key ( :home , id ) )
448+ Redis . current . del ( reblog_key )
449+
450+ reblogged_id_set . each do |reblogged_id |
451+ reblog_set_key = FeedManager . instance . key ( :home , id , "reblogs:#{ reblogged_id } " )
452+ Redis . current . del ( reblog_set_key )
453+ end
454+ end
455+ end
481456end
0 commit comments