DEV: Compatibility with TruffleRuby (#16864)

Removes thread unsafe lazy initialization.
See https://meta.discourse.org/t/225447

It also removes an unused variable in `FlagSettings`.
This commit is contained in:
Gerhard Schlager 2022-05-19 21:56:55 +02:00 committed by GitHub
parent 166fe3bb34
commit 0af05c2682
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 45 deletions

View File

@ -12,51 +12,14 @@ class PostActionType < ActiveRecord::Base
end
class << self
def flag_settings
unless @flag_settings
@flag_settings = FlagSettings.new
@flag_settings.add(
3,
:off_topic,
notify_type: true,
auto_action_type: true,
)
@flag_settings.add(
4,
:inappropriate,
topic_type: true,
notify_type: true,
auto_action_type: true,
)
@flag_settings.add(
8,
:spam,
topic_type: true,
notify_type: true,
auto_action_type: true,
)
@flag_settings.add(
6,
:notify_user,
topic_type: false,
notify_type: false,
custom_type: true
)
@flag_settings.add(
7,
:notify_moderators,
topic_type: true,
notify_type: true,
custom_type: true
)
end
@flag_settings
end
attr_reader :flag_settings
def replace_flag_settings(settings)
if settings
@flag_settings = settings
else
initialize_flag_settings
end
@types = nil
end
@ -117,9 +80,51 @@ class PostActionType < ActiveRecord::Base
def is_flag?(sym)
flag_types.valid?(sym)
end
private
def initialize_flag_settings
@flag_settings = FlagSettings.new
@flag_settings.add(
3,
:off_topic,
notify_type: true,
auto_action_type: true,
)
@flag_settings.add(
4,
:inappropriate,
topic_type: true,
notify_type: true,
auto_action_type: true,
)
@flag_settings.add(
8,
:spam,
topic_type: true,
notify_type: true,
auto_action_type: true,
)
@flag_settings.add(
6,
:notify_user,
topic_type: false,
notify_type: false,
custom_type: true
)
@flag_settings.add(
7,
:notify_moderators,
topic_type: true,
notify_type: true,
custom_type: true
)
end
end
initialize_flag_settings
end
# == Schema Information
#
# Table name: post_action_types

View File

@ -20,8 +20,6 @@ class FlagSettings
end
def add(id, name, topic_type: nil, notify_type: nil, auto_action_type: nil, custom_type: nil)
details ||= {}
@all_flag_types[name] = id
@topic_flag_types[name] = id if !!topic_type
@notify_types[name] = id if !!notify_type