Merge remote-tracking branch 'parent/main' into upstream-20240126

This commit is contained in:
KMY 2024-01-26 11:14:21 +09:00
commit 3dd9591a4b
163 changed files with 3000 additions and 2777 deletions

View file

@ -71,16 +71,7 @@ class CustomFilter < ApplicationRecord
scope = CustomFilterKeyword.includes(:custom_filter).where(custom_filter: { account_id: account_id }).where(Arel.sql('expires_at IS NULL OR expires_at > NOW()'))
scope.to_a.group_by(&:custom_filter).each do |filter, keywords|
keywords.map! do |keyword|
if keyword.whole_word
sb = /\A[[:word:]]/.match?(keyword.keyword) ? '\b' : ''
eb = /[[:word:]]\z/.match?(keyword.keyword) ? '\b' : ''
/(?mix:#{sb}#{Regexp.escape(keyword.keyword)}#{eb})/
else
/#{Regexp.escape(keyword.keyword)}/i
end
end
keywords.map!(&:to_regex)
filters_hash[filter.id] = { keywords: Regexp.union(keywords), filter: filter }
end.to_h

View file

@ -23,8 +23,24 @@ class CustomFilterKeyword < ApplicationRecord
before_destroy :prepare_cache_invalidation!
after_commit :invalidate_cache!
def to_regex
if whole_word?
/(?mix:#{to_regex_sb}#{Regexp.escape(keyword)}#{to_regex_eb})/
else
/#{Regexp.escape(keyword)}/i
end
end
private
def to_regex_sb
/\A[[:word:]]/.match?(keyword) ? '\b' : ''
end
def to_regex_eb
/[[:word:]]\z/.match?(keyword) ? '\b' : ''
end
def prepare_cache_invalidation!
custom_filter.prepare_cache_invalidation!
end

View file

@ -27,11 +27,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