FIX: refresh flags cache after update (#27909)

`after_commit` should be used before refreshing processes to be sure that the database is already updated.

Also, MessageBus is used instead of events as MessageBus works correctly with many processes;
This commit is contained in:
Krzysztof Kotlarek 2024-07-15 19:45:25 +10:00 committed by GitHub
parent 4d64205eef
commit 25485bddee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 5 deletions

View File

@ -10,8 +10,7 @@ class Flag < ActiveRecord::Base
before_save :set_position
before_save :set_name_key
after_save :reset_flag_settings!
after_destroy :reset_flag_settings!
after_commit :reset_flag_settings!
default_scope { order(:position).where(score_type: false) }
@ -27,7 +26,7 @@ class Flag < ActiveRecord::Base
def self.reset_flag_settings!
# Flags are memoized for better performance. After the update, we need to reload them in all processes.
PostActionType.reload_types
DiscourseEvent.trigger(:reload_post_action_types)
MessageBus.publish("/reload_post_action_types", {})
end
def system?

View File

@ -11,8 +11,6 @@ class PostActionType < ActiveRecord::Base
ApplicationSerializer.expire_cache_fragment!(/\Apost_action_flag_types_/)
end
DiscourseEvent.on(:reload_post_action_types) { self.reload_types }
class << self
attr_reader :flag_settings

View File

@ -132,3 +132,7 @@ if Rails.env == "test" || $0 =~ /rake$/
# disable keepalive in testing
MessageBus.keepalive_interval = -1
end
if !Rails.env.test?
MessageBus.subscribe("/reload_post_action_types") { PostActionType.reload_types }
end