account_domain_block.rb 891 B

12345678910111213141516171819202122232425262728293031323334
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: account_domain_blocks
  5. #
  6. # id :bigint(8) not null, primary key
  7. # domain :string
  8. # created_at :datetime not null
  9. # updated_at :datetime not null
  10. # account_id :bigint(8)
  11. #
  12. class AccountDomainBlock < ApplicationRecord
  13. include Paginable
  14. include DomainNormalizable
  15. belongs_to :account
  16. validates :domain, presence: true, uniqueness: { scope: :account_id }, domain: true
  17. after_commit :invalidate_domain_blocking_cache
  18. after_commit :invalidate_follow_recommendations_cache
  19. private
  20. def invalidate_domain_blocking_cache
  21. Rails.cache.delete("exclude_domains_for:#{account_id}")
  22. Rails.cache.delete(['exclude_domains', account_id, domain])
  23. end
  24. def invalidate_follow_recommendations_cache
  25. Rails.cache.delete("follow_recommendations/#{account_id}")
  26. end
  27. end