0
0
Fork 0

Add specs for Instance model scopes and add with_domain_follows scope (#28767)

This commit is contained in:
Matt Jankowski 2024-01-25 10:28:27 -05:00 committed by GitHub
parent 4cdf62e576
commit 42ab855b23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 123 additions and 1 deletions

View file

@ -25,11 +25,25 @@ class Instance < ApplicationRecord
scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
scope :domain_starts_with, ->(value) { where(arel_table[:domain].matches("#{sanitize_sql_like(value)}%", false, true)) }
scope :by_domain_and_subdomains, ->(domain) { where("reverse('.' || domain) LIKE reverse(?)", "%.#{domain}") }
scope :with_domain_follows, ->(domains) { where(domain: domains).where(domain_account_follows) }
def self.refresh
Scenic.database.refresh_materialized_view(table_name, concurrently: true, cascade: false)
end
def self.domain_account_follows
Arel.sql(
<<~SQL.squish
EXISTS (
SELECT 1
FROM follows
JOIN accounts ON follows.account_id = accounts.id OR follows.target_account_id = accounts.id
WHERE accounts.domain = instances.domain
)
SQL
)
end
def readonly?
true
end