Change hashtag trends to be stored in the database instead of redis (#32837)
Co-authored-by: David Roetzel <david@roetzel.de>
This commit is contained in:
parent
b9b26490e7
commit
48ea7552dd
18 changed files with 195 additions and 157 deletions
25
db/post_migrate/20241123160722_move_tag_trends_to_table.rb
Normal file
25
db/post_migrate/20241123160722_move_tag_trends_to_table.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class MoveTagTrendsToTable < ActiveRecord::Migration[7.2]
|
||||
include Redisable
|
||||
|
||||
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?
|
||||
)
|
||||
end
|
||||
|
||||
TagTrend.recalculate_ordered_rank
|
||||
|
||||
redis.del('trending_tags:allowed', 'trending_tags:all')
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue