mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Skip whisper posts when updating topic like count (#10157)
This commit is contained in:
23
db/migrate/20200707154522_fix_topic_like_count.rb
Normal file
23
db/migrate/20200707154522_fix_topic_like_count.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class FixTopicLikeCount < ActiveRecord::Migration[6.0]
|
||||
def up
|
||||
return if DB.query_single("SELECT * FROM site_settings WHERE name = 'enable_whispers' AND value = 't'").empty?
|
||||
|
||||
DB.exec(<<~SQL, whisper: Post.types[:whisper])
|
||||
UPDATE topics SET like_count = tbl.like_count
|
||||
FROM (
|
||||
SELECT topic_id, SUM(like_count) like_count
|
||||
FROM posts
|
||||
WHERE deleted_at IS NULL AND post_type <> :whisper
|
||||
GROUP BY topic_id
|
||||
) AS tbl
|
||||
WHERE topics.id = tbl.topic_id
|
||||
AND topics.like_count <> tbl.like_count
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user