Revert "Rails 7 update" (#25667)
This commit is contained in:
parent
5b46345459
commit
ba06a2f104
22 changed files with 144 additions and 242 deletions
|
@ -80,7 +80,7 @@ class Announcement < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
ActiveRecord::Associations::Preloader.new(records: records, associations: :custom_emoji)
|
||||
ActiveRecord::Associations::Preloader.new.preload(records, :custom_emoji)
|
||||
records
|
||||
end
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ module AccountSearch
|
|||
tsquery = generate_query_for_search(terms)
|
||||
|
||||
find_by_sql([BASIC_SEARCH_SQL, { limit: limit, offset: offset, tsquery: tsquery }]).tap do |records|
|
||||
ActiveRecord::Associations::Preloader.new(records: records, associations: :account_stat)
|
||||
ActiveRecord::Associations::Preloader.new.preload(records, :account_stat)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -131,7 +131,7 @@ module AccountSearch
|
|||
sql_template = following ? ADVANCED_SEARCH_WITH_FOLLOWING : ADVANCED_SEARCH_WITHOUT_FOLLOWING
|
||||
|
||||
find_by_sql([sql_template, { id: account.id, limit: limit, offset: offset, tsquery: tsquery }]).tap do |records|
|
||||
ActiveRecord::Associations::Preloader.new(records: records, associations: :account_stat)
|
||||
ActiveRecord::Associations::Preloader.new.preload(records, :account_stat)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,41 +4,41 @@ module StatusSafeReblogInsert
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
# This patch overwrites the built-in ActiveRecord `_insert_record` method to
|
||||
# ensure that no reblogs of discarded statuses are created, as this cannot be
|
||||
# enforced through DB constraints the same way as reblogs of deleted statuses
|
||||
# This is a hack to ensure that no reblogs of discarded statuses are created,
|
||||
# as this cannot be enforced through database constraints the same way we do
|
||||
# for reblogs of deleted statuses.
|
||||
#
|
||||
# We redefine the internal method responsible for issuing the `INSERT`
|
||||
# statement and replace the `INSERT INTO ... VALUES ...` query with an `INSERT
|
||||
# INTO ... SELECT ...` query with a `WHERE deleted_at IS NULL` clause on the
|
||||
# reblogged status to ensure consistency at the database level.
|
||||
# To achieve this, we redefine the internal method responsible for issuing
|
||||
# the "INSERT" statement and replace the "INSERT INTO ... VALUES ..." query
|
||||
# with an "INSERT INTO ... SELECT ..." query with a "WHERE deleted_at IS NULL"
|
||||
# clause on the reblogged status to ensure consistency at the database level.
|
||||
#
|
||||
# The code is kept similar to ActiveRecord::Persistence code and calls it
|
||||
# directly when we are not handling a reblog.
|
||||
# Otherwise, the code is kept as close as possible to ActiveRecord::Persistence
|
||||
# code, and actually calls it if we are not handling a reblog.
|
||||
def _insert_record(values)
|
||||
return super unless values.is_a?(Hash) && values['reblog_of_id']&.value.present?
|
||||
return super unless values.is_a?(Hash) && values['reblog_of_id'].present?
|
||||
|
||||
primary_key = self.primary_key
|
||||
primary_key_value = nil
|
||||
|
||||
if prefetch_primary_key? && primary_key
|
||||
values[primary_key] ||= begin
|
||||
if primary_key
|
||||
primary_key_value = values[primary_key]
|
||||
|
||||
if !primary_key_value && prefetch_primary_key?
|
||||
primary_key_value = next_sequence_value
|
||||
_default_attributes[primary_key].with_cast_value(primary_key_value)
|
||||
values[primary_key] = primary_key_value
|
||||
end
|
||||
end
|
||||
|
||||
# The following line departs from stock ActiveRecord
|
||||
# Original code was:
|
||||
# im.insert(values.transform_keys { |name| arel_table[name] })
|
||||
# Instead, we use a custom builder when a reblog is happening:
|
||||
# The following line is where we differ from stock ActiveRecord implementation
|
||||
im = _compile_reblog_insert(values)
|
||||
|
||||
connection.insert(im, "#{self} Create", primary_key || false, primary_key_value).tap do |result|
|
||||
# Since we are using SELECT instead of VALUES, a non-error `nil` return is possible.
|
||||
# For our purposes, it's equivalent to a foreign key constraint violation
|
||||
raise ActiveRecord::InvalidForeignKey, "(reblog_of_id)=(#{values['reblog_of_id'].value}) is not present in table \"statuses\"" if result.nil?
|
||||
end
|
||||
# Since we are using SELECT instead of VALUES, a non-error `nil` return is possible.
|
||||
# For our purposes, it's equivalent to a foreign key constraint violation
|
||||
result = connection.insert(im, "#{self} Create", primary_key || false, primary_key_value)
|
||||
raise ActiveRecord::InvalidForeignKey, "(reblog_of_id)=(#{values['reblog_of_id']}) is not present in table \"statuses\"" if result.nil?
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
def _compile_reblog_insert(values)
|
||||
|
@ -54,9 +54,9 @@ module StatusSafeReblogInsert
|
|||
|
||||
binds = []
|
||||
reblog_bind = nil
|
||||
values.each do |name, attribute|
|
||||
values.each do |name, value|
|
||||
attr = arel_table[name]
|
||||
bind = predicate_builder.build_bind_attribute(attr.name, attribute.value)
|
||||
bind = predicate_builder.build_bind_attribute(attr.name, value)
|
||||
|
||||
im.columns << attr
|
||||
binds << bind
|
||||
|
|
|
@ -111,7 +111,7 @@ class Notification < ApplicationRecord
|
|||
|
||||
# Instead of using the usual `includes`, manually preload each type.
|
||||
# If polymorphic associations are loaded with the usual `includes`, other types of associations will be loaded more.
|
||||
ActiveRecord::Associations::Preloader.new(records: grouped_notifications, associations: associations)
|
||||
ActiveRecord::Associations::Preloader.new.preload(grouped_notifications, associations)
|
||||
end
|
||||
|
||||
unique_target_statuses = notifications.filter_map(&:target_status).uniq
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue