BUGFIX: when RTT is short likes may not appear to work

BUGFIX: site settings db provider not triggering updates
  at the correct point
This commit is contained in:
Sam 2014-03-31 12:34:01 +11:00
parent 8fc2549873
commit 9aec32688b
3 changed files with 21 additions and 12 deletions

View File

@ -20,7 +20,7 @@ class PostAction < ActiveRecord::Base
after_save :update_counters
after_save :enforce_rules
after_save :notify_subscribers
after_commit :notify_subscribers
def self.update_flagged_posts_count
posts_flagged_count = PostAction.joins(post: :topic)
@ -154,7 +154,10 @@ class PostAction < ActiveRecord::Base
def remove_act!(user)
trash!(user)
run_callbacks(:save)
# NOTE: save is called to ensure all callbacks are called
# trash will not trigger callbacks, and triggering after_commit
# is not trivial
save
end
def is_bookmark?

View File

@ -214,8 +214,10 @@ module SiteSettingExtension
provider.save(name, val, type)
current[name] = convert(val, type)
clear_cache!
end
@last_message_sent = MessageBus.publish('/site_settings', {process: process_id})
def notify_changed!
MessageBus.publish('/site_settings', {process: process_id})
end
def has_setting?(name)

View File

@ -3,6 +3,10 @@ module SiteSettings; end
class SiteSettings::DbProvider
def initialize(model)
model.after_commit do
model.notify_changed!
end
@model = model
end
@ -28,18 +32,18 @@ class SiteSettings::DbProvider
return unless table_exists?
count = @model.where({
model = @model.find_by({
name: name
}).update_all({
name: name,
value: value,
data_type: data_type,
updated_at: Time.now
})
if count == 0
@model.create!(name: name, value: value, data_type: data_type)
end
model ||= @model.new
model.name = name
model.value = value
model.data_type = data_type
# save! used to ensure after_commit is called
model.save!
true
end