Upgrade to latest redis-rb 4.x and fix deprecations (#23616)

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
This commit is contained in:
Jean byroot Boussier 2023-03-04 16:38:28 +01:00 committed by GitHub
parent aa98c8fbeb
commit 922837dc96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 37 additions and 38 deletions

View file

@ -20,7 +20,7 @@ class Scheduler::FollowRecommendationsScheduler
Trends.available_locales.each do |locale|
recommendations = if AccountSummary.safe.filtered.localized(locale).exists? # We can skip the work if no accounts with that language exist
FollowRecommendation.localized(locale).order(rank: :desc).limit(SET_SIZE).map { |recommendation| [recommendation.account_id, recommendation.rank] }
FollowRecommendation.localized(locale).order(rank: :desc).limit(SET_SIZE).map { |recommendation| [recommendation.rank, recommendation.account_id] }
else
[]
end
@ -33,14 +33,14 @@ class Scheduler::FollowRecommendationsScheduler
# Language-specific results should be above language-agnostic ones,
# otherwise language-agnostic ones will always overshadow them
recommendations.map! { |(account_id, rank)| [account_id, rank + max_fallback_rank] }
recommendations.map! { |(rank, account_id)| [rank + max_fallback_rank, account_id] }
added = 0
fallback_recommendations.each do |recommendation|
next if recommendations.any? { |(account_id, _)| account_id == recommendation.account_id }
next if recommendations.any? { |(_, account_id)| account_id == recommendation.account_id }
recommendations << [recommendation.account_id, recommendation.rank]
recommendations << [recommendation.rank, recommendation.account_id]
added += 1
break if added >= missing
@ -49,10 +49,7 @@ class Scheduler::FollowRecommendationsScheduler
redis.multi do |multi|
multi.del(key(locale))
recommendations.each do |(account_id, rank)|
multi.zadd(key(locale), rank, account_id)
end
multi.zadd(key(locale), recommendations)
end
end
end