0
0
Fork 0

Extract scenic view model common methods to concern (#28111)

This commit is contained in:
Matt Jankowski 2024-02-06 04:08:07 -05:00 committed by GitHub
parent 1666b19559
commit 86500e3312
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 34 additions and 33 deletions

View file

@ -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