Fix tag trend migration failing due to duplicate rows (#33189)

This commit is contained in:
Eugen Rochko 2024-12-05 17:12:26 +01:00 committed by GitHub
parent 17c02c9210
commit d29eddc401
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,12 +6,8 @@ class MoveTagTrendsToTable < ActiveRecord::Migration[7.2]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
redis.zrange('trending_tags:all', 0, -1, with_scores: true).each do |(tag_id, score)| redis.zrange('trending_tags:all', 0, -1, with_scores: true).each_slice(1_000) do |data|
TagTrend.create( TagTrend.upsert_all(data.map { |(tag_id, score)| { tag_id: tag_id, score: score, language: '', allowed: redis.zscore('trending_tags:allowed', tag_id).present? } }, unique_by: %w(tag_id language))
tag_id: tag_id,
score: score,
allowed: redis.zscore('trending_tags:allowed', tag_id).present?
)
end end
TagTrend.recalculate_ordered_rank TagTrend.recalculate_ordered_rank