Fix queries count in fan_out antennas
This commit is contained in:
parent
b527b68958
commit
9db152db38
5 changed files with 43 additions and 25 deletions
|
@ -18,6 +18,8 @@
|
|||
# min_reblogs :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# min_emojis :integer
|
||||
# keep_self_emoji :boolean default(TRUE), not null
|
||||
#
|
||||
class AccountStatusesCleanupPolicy < ApplicationRecord
|
||||
include Redisable
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
# updated_at :datetime not null
|
||||
# expires_at :datetime
|
||||
# with_media_only :boolean default(FALSE), not null
|
||||
# exclude_domains :jsonb
|
||||
# exclude_accounts :jsonb
|
||||
# exclude_tags :jsonb
|
||||
#
|
||||
class Antenna < ApplicationRecord
|
||||
include Expireable
|
||||
|
@ -86,7 +89,7 @@ class Antenna < ApplicationRecord
|
|||
def keywords_raw=(raw)
|
||||
keywords = raw.split(/\R/).filter { |r| r.present? && r.length >= 2 }.uniq
|
||||
self[:keywords] = keywords
|
||||
self[:any_keywords] = !keywords.any? && !exclude_keywords&.any?
|
||||
self[:any_keywords] = !keywords.any?
|
||||
end
|
||||
|
||||
def exclude_keywords_raw
|
||||
|
@ -98,7 +101,6 @@ class Antenna < ApplicationRecord
|
|||
def exclude_keywords_raw=(raw)
|
||||
exclude_keywords = raw.split(/\R/).filter { |r| r.present? }.uniq
|
||||
self[:exclude_keywords] = exclude_keywords
|
||||
self[:any_keywords] = !keywords&.any? && !exclude_keywords.any?
|
||||
end
|
||||
|
||||
def tags_raw
|
||||
|
@ -118,18 +120,19 @@ class Antenna < ApplicationRecord
|
|||
end
|
||||
|
||||
def exclude_tags_raw
|
||||
antenna_tags.where(exclude: true).map(&:tag).map(&:name).join("\n")
|
||||
return '' if !exclude_tags.present?
|
||||
Tag.where(id: exclude_tags).map(&:name).join("\n")
|
||||
end
|
||||
|
||||
def exclude_tags_raw=(raw)
|
||||
return if exclude_tags_raw == raw
|
||||
|
||||
tags = []
|
||||
tag_names = raw.split(/\R/).filter { |r| r.present? }.map { |r| r.start_with?('#') ? r[1..-1] : r }.uniq
|
||||
|
||||
antenna_tags.where(exclude: true).destroy_all
|
||||
Tag.find_or_create_by_names(tag_names).each do |tag|
|
||||
antenna_tags.create!(tag: tag, exclude: true)
|
||||
tags << tag.id
|
||||
end
|
||||
self[:exclude_tags] = tags
|
||||
end
|
||||
|
||||
def domains_raw
|
||||
|
@ -149,18 +152,15 @@ class Antenna < ApplicationRecord
|
|||
end
|
||||
|
||||
def exclude_domains_raw
|
||||
antenna_domains.where(exclude: true).map(&:name).join("\n")
|
||||
return '' if !exclude_domains.present?
|
||||
exclude_domains.join("\n")
|
||||
end
|
||||
|
||||
def exclude_domains_raw=(raw)
|
||||
return if exclude_domains_raw == raw
|
||||
|
||||
domain_names = raw.split(/\R/).filter { |r| r.present? }.uniq
|
||||
|
||||
antenna_domains.where(exclude: true).destroy_all
|
||||
domain_names.each do |domain|
|
||||
antenna_domains.create!(name: domain, exclude: true)
|
||||
end
|
||||
self[:exclude_domains] = domain_names
|
||||
end
|
||||
|
||||
def accounts_raw
|
||||
|
@ -186,7 +186,8 @@ class Antenna < ApplicationRecord
|
|||
end
|
||||
|
||||
def exclude_accounts_raw
|
||||
antenna_accounts.where(exclude: true).map(&:account).map { |account| account.domain ? "@#{account.username}@#{account.domain}" : "@#{account.username}" }.join("\n")
|
||||
return '' if !exclude_accounts.present?
|
||||
Account.where(id: exclude_accounts).map { |account| account.domain ? "@#{account.username}@#{account.domain}" : "@#{account.username}" }.join("\n")
|
||||
end
|
||||
|
||||
def exclude_accounts_raw=(raw)
|
||||
|
@ -194,16 +195,15 @@ class Antenna < ApplicationRecord
|
|||
|
||||
account_names = raw.split(/\R/).filter { |r| r.present? }.map { |r| r.start_with?('@') ? r[1..-1] : r }.uniq
|
||||
|
||||
hit = false
|
||||
antenna_accounts.where(exclude: true).destroy_all
|
||||
accounts = []
|
||||
account_names.each do |name|
|
||||
username, domain = name.split('@')
|
||||
account = Account.find_by(username: username, domain: domain)
|
||||
if account.present?
|
||||
antenna_accounts.create!(account: account, exclude: true)
|
||||
hit = true
|
||||
accounts << account.id
|
||||
end
|
||||
end
|
||||
self[:exclude_accounts] = accounts
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue