mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 11:47:15 +08:00
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:

committed by
GitHub

parent
4d64205eef
commit
25485bddee
@ -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?
|
||||
|
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user