Fix tag trend migration failing due to duplicate rows (#33189)
This commit is contained in:
		@@ -6,12 +6,8 @@ class MoveTagTrendsToTable < ActiveRecord::Migration[7.2]
 | 
			
		||||
  disable_ddl_transaction!
 | 
			
		||||
 | 
			
		||||
  def up
 | 
			
		||||
    redis.zrange('trending_tags:all', 0, -1, with_scores: true).each do |(tag_id, score)|
 | 
			
		||||
      TagTrend.create(
 | 
			
		||||
        tag_id: tag_id,
 | 
			
		||||
        score: score,
 | 
			
		||||
        allowed: redis.zscore('trending_tags:allowed', tag_id).present?
 | 
			
		||||
      )
 | 
			
		||||
    redis.zrange('trending_tags:all', 0, -1, with_scores: true).each_slice(1_000) do |data|
 | 
			
		||||
      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))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    TagTrend.recalculate_ordered_rank
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user