diff --git a/app/assets/javascripts/discourse/views/topic-list-item.js.es6 b/app/assets/javascripts/discourse/views/topic-list-item.js.es6 index 6a4391ad46f..e03789e220d 100644 --- a/app/assets/javascripts/discourse/views/topic-list-item.js.es6 +++ b/app/assets/javascripts/discourse/views/topic-list-item.js.es6 @@ -4,7 +4,12 @@ export default Discourse.View.extend(StringBuffer, { rerenderTriggers: ['controller.bulkSelectEnabled', 'topic.pinned'], tagName: 'tr', rawTemplate: 'list/topic_list_item.raw', - classNameBindings: ['controller.checked', 'content.archived', ':topic-list-item', 'content.hasExcerpt:has-excerpt'], + classNameBindings: ['controller.checked', + 'content.archived', + ':topic-list-item', + 'content.hasExcerpt:has-excerpt', + 'content.liked:liked', + 'content.bookmarked:bookmarked'], attributeBindings: ['data-topic-id'], 'data-topic-id': Em.computed.alias('content.id'), titleColSpan: function(){ diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 1ec92a8c1e1..b271e24bda1 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -384,7 +384,16 @@ class PostAction < ActiveRecord::Base Post.where(id: post_id).update_all ["#{column} = ?", count] end + topic_id = Post.with_deleted.where(id: post_id).pluck(:topic_id).first + + # topic_user + if [:like,:bookmark].include? post_action_type_key + TopicUser.update_post_action_cache(user_id: user_id, + topic_id: topic_id, + post_action_type: post_action_type_key) + end + topic_count = Post.where(topic_id: topic_id).sum(column) Topic.where(id: topic_id).update_all ["#{column} = ?", topic_count] diff --git a/app/models/topic_user.rb b/app/models/topic_user.rb index 5a56d1a37b0..a0768e1c10d 100644 --- a/app/models/topic_user.rb +++ b/app/models/topic_user.rb @@ -229,7 +229,60 @@ class TopicUser < ActiveRecord::Base end end + def self.update_post_action_cache(opts={}) + user_id = opts[:user_id] + topic_id = opts[:topic_id] + action_type = opts[:post_action_type] + + action_type_name = "liked" if action_type == :like + action_type_name = "bookmarked" if action_type == :bookmark + + raise ArgumentError, "action_type" if action_type && !action_type_name + + unless action_type_name + update_post_action_cache(opts.merge(post_action_type: :like)) + update_post_action_cache(opts.merge(post_action_type: :bookmark)) + return + end + + builder = SqlBuilder.new <