From 588667b1e45b87dae5f88debb85c259aac8fa2fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 30 Mar 2015 12:31:10 +0200 Subject: [PATCH] FEATURE: fix avatar in quotes when changing avatars --- app/jobs/regular/fix_avatar_in_quotes.rb | 11 +++++++++++ app/models/user.rb | 2 ++ 2 files changed, 13 insertions(+) create mode 100644 app/jobs/regular/fix_avatar_in_quotes.rb diff --git a/app/jobs/regular/fix_avatar_in_quotes.rb b/app/jobs/regular/fix_avatar_in_quotes.rb new file mode 100644 index 00000000000..a5288254b18 --- /dev/null +++ b/app/jobs/regular/fix_avatar_in_quotes.rb @@ -0,0 +1,11 @@ +module Jobs + class FixAvatarInQuotes < Jobs::Base + + def execute(args) + user = User.find(args[:user_id]) + post_ids_to_rebake = Post.exec_sql("SELECT post_id FROM quoted_posts WHERE quoted_post_id IN (SELECT id FROM posts WHERE user_id = ?)", user.id).values.flatten.map(&:to_i) + Post.where(id: post_ids_to_rebake).find_each.map(&:rebake!) + end + + end +end diff --git a/app/models/user.rb b/app/models/user.rb index d93301150a0..b49f332d21a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -645,6 +645,8 @@ class User < ActiveRecord::Base if SiteSetting.automatically_download_gravatars? && !avatar.last_gravatar_download_attempt Jobs.enqueue(:update_gravatar, user_id: self.id, avatar_id: avatar.id) end + + Jobs.enqueue(:fix_avatar_in_quotes, user_id: self.id) end def first_post_created_at