]> cat aescling's git repositories - mastodon.git/blob - app/models/block.rb
Fix records not being indexed sometimes (#12024)
[mastodon.git] / app / models / block.rb
1 # frozen_string_literal: true
2 # == Schema Information
3 #
4 # Table name: blocks
5 #
6 # id :bigint(8) not null, primary key
7 # created_at :datetime not null
8 # updated_at :datetime not null
9 # account_id :bigint(8) not null
10 # target_account_id :bigint(8) not null
11 # uri :string
12 #
13
14 class Block < ApplicationRecord
15 include Paginable
16 include RelationshipCacheable
17
18 belongs_to :account
19 belongs_to :target_account, class_name: 'Account'
20
21 validates :account_id, uniqueness: { scope: :target_account_id }
22
23 def local?
24 false # Force uri_for to use uri attribute
25 end
26
27 after_commit :remove_blocking_cache
28 before_validation :set_uri, only: :create
29
30 private
31
32 def remove_blocking_cache
33 Rails.cache.delete("exclude_account_ids_for:#{account_id}")
34 Rails.cache.delete("exclude_account_ids_for:#{target_account_id}")
35 end
36
37 def set_uri
38 self.uri = ActivityPub::TagManager.instance.generate_uri_for(self) if uri.nil?
39 end
40 end
This page took 0.08684 seconds and 4 git commands to generate.