mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 04:03:57 -06:00
4aa9a813ec
Non-staff users are not allowed to see whisper so this change prevents
non-staff user from seeing a like count that does not make sense to
them. In the future, we might consider adding another like count column
for staff user.
Follow-up to 4492718864
25 lines
582 B
Ruby
25 lines
582 B
Ruby
# frozen_string_literal: true
|
|
|
|
class FixTopicLikeCountIncludingWhispers < ActiveRecord::Migration[6.0]
|
|
def up
|
|
whisper_post_type = 4
|
|
|
|
DB.exec(<<~SQL)
|
|
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_post_type}
|
|
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
|