Merge remote-tracking branch 'parent/main' into upstream-20230209
This commit is contained in:
commit
05e52a09a8
188 changed files with 2810 additions and 1295 deletions
|
@ -31,12 +31,12 @@ class AccountSuggestions
|
|||
account_ids = account_ids_with_sources[offset, limit]
|
||||
accounts_map = Account.where(id: account_ids.map(&:first)).includes(:account_stat, :user).index_by(&:id)
|
||||
|
||||
account_ids.filter_map do |(account_id, source)|
|
||||
account_ids.filter_map do |(account_id, sources)|
|
||||
next unless accounts_map.key?(account_id)
|
||||
|
||||
AccountSuggestions::Suggestion.new(
|
||||
account: accounts_map[account_id],
|
||||
source: source
|
||||
sources: sources
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AccountSuggestions::Suggestion < ActiveModelSerializers::Model
|
||||
attributes :account, :source
|
||||
attributes :account, :sources
|
||||
|
||||
delegate :id, to: :account, prefix: true
|
||||
end
|
||||
|
|
|
@ -10,21 +10,13 @@
|
|||
#
|
||||
|
||||
class AccountSummary < ApplicationRecord
|
||||
include DatabaseViewRecord
|
||||
|
||||
self.primary_key = :account_id
|
||||
|
||||
has_many :follow_recommendation_suppressions, primary_key: :account_id, foreign_key: :account_id, inverse_of: false
|
||||
has_many :follow_recommendation_suppressions, primary_key: :account_id, foreign_key: :account_id, inverse_of: false, dependent: nil
|
||||
|
||||
scope :safe, -> { where(sensitive: false) }
|
||||
scope :localized, ->(locale) { order(Arel::Nodes::Case.new.when(arel_table[:language].eq(locale)).then(1).else(0).desc) }
|
||||
scope :filtered, -> { where.missing(:follow_recommendation_suppressions) }
|
||||
|
||||
def self.refresh
|
||||
Scenic.database.refresh_materialized_view(table_name, concurrently: true, cascade: false)
|
||||
rescue ActiveRecord::StatementInvalid
|
||||
Scenic.database.refresh_materialized_view(table_name, concurrently: false, cascade: false)
|
||||
end
|
||||
|
||||
def readonly?
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
25
app/models/concerns/database_view_record.rb
Normal file
25
app/models/concerns/database_view_record.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DatabaseViewRecord
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
def refresh
|
||||
Scenic.database.refresh_materialized_view(
|
||||
table_name,
|
||||
concurrently: true,
|
||||
cascade: false
|
||||
)
|
||||
rescue ActiveRecord::StatementInvalid
|
||||
Scenic.database.refresh_materialized_view(
|
||||
table_name,
|
||||
concurrently: false,
|
||||
cascade: false
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def readonly?
|
||||
true
|
||||
end
|
||||
end
|
|
@ -10,6 +10,8 @@
|
|||
#
|
||||
|
||||
class FollowRecommendation < ApplicationRecord
|
||||
include DatabaseViewRecord
|
||||
|
||||
self.primary_key = :account_id
|
||||
self.table_name = :global_follow_recommendations
|
||||
|
||||
|
@ -17,14 +19,4 @@ class FollowRecommendation < ApplicationRecord
|
|||
belongs_to :account
|
||||
|
||||
scope :localized, ->(locale) { joins(:account_summary).merge(AccountSummary.localized(locale)) }
|
||||
|
||||
def self.refresh
|
||||
Scenic.database.refresh_materialized_view(table_name, concurrently: true, cascade: false)
|
||||
rescue ActiveRecord::StatementInvalid
|
||||
Scenic.database.refresh_materialized_view(table_name, concurrently: false, cascade: false)
|
||||
end
|
||||
|
||||
def readonly?
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#
|
||||
|
||||
class Instance < ApplicationRecord
|
||||
include DatabaseViewRecord
|
||||
|
||||
self.primary_key = :domain
|
||||
|
||||
attr_accessor :failure_days
|
||||
|
@ -29,10 +31,6 @@ class Instance < ApplicationRecord
|
|||
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
|
||||
|
@ -46,10 +44,6 @@ class Instance < ApplicationRecord
|
|||
)
|
||||
end
|
||||
|
||||
def readonly?
|
||||
true
|
||||
end
|
||||
|
||||
def delivery_failure_tracker
|
||||
@delivery_failure_tracker ||= DeliveryFailureTracker.new(domain)
|
||||
end
|
||||
|
|
|
@ -47,9 +47,9 @@ class Report < ApplicationRecord
|
|||
delegate :local?, to: :account
|
||||
|
||||
validates :comment, length: { maximum: 1_000 }, if: :local?
|
||||
validates :rule_ids, absence: true, unless: :violation?
|
||||
validates :rule_ids, absence: true, if: -> { (category_changed? || rule_ids_changed?) && !violation? }
|
||||
|
||||
validate :validate_rule_ids
|
||||
validate :validate_rule_ids, if: -> { (category_changed? || rule_ids_changed?) && violation? }
|
||||
|
||||
# entries here need to be kept in sync with the front-end:
|
||||
# - app/javascript/mastodon/features/notifications/components/report.jsx
|
||||
|
@ -162,8 +162,6 @@ class Report < ApplicationRecord
|
|||
end
|
||||
|
||||
def validate_rule_ids
|
||||
return unless violation?
|
||||
|
||||
errors.add(:rule_ids, I18n.t('reports.errors.invalid_rules')) unless rules.size == rule_ids&.size
|
||||
end
|
||||
|
||||
|
|
|
@ -10,11 +10,9 @@
|
|||
#
|
||||
|
||||
class UserIp < ApplicationRecord
|
||||
include DatabaseViewRecord
|
||||
|
||||
self.primary_key = :user_id
|
||||
|
||||
belongs_to :user
|
||||
|
||||
def readonly?
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue