Add trending statuses (#17431)
* Add trending statuses * Fix dangling items with stale scores in localized sets * Various fixes and improvements - Change approve_all/reject_all to approve_accounts/reject_accounts - Change Trends::Query methods to not mutate the original query - Change Trends::Query#skip to offset - Change follow recommendations to be refreshed in a transaction * Add tests for trending statuses filtering behaviour * Fix not applying filtering scope in controller
This commit is contained in:
parent
a29a982eaa
commit
27965ce5ed
71 changed files with 1074 additions and 307 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
class Trends::Base
|
||||
include Redisable
|
||||
include LanguagesHelper
|
||||
|
||||
class_attribute :default_options
|
||||
|
||||
|
@ -32,8 +33,8 @@ class Trends::Base
|
|||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def get(*)
|
||||
raise NotImplementedError
|
||||
def query
|
||||
Trends::Query.new(key_prefix, klass)
|
||||
end
|
||||
|
||||
def score(id)
|
||||
|
@ -72,6 +73,21 @@ class Trends::Base
|
|||
redis.zrevrange("#{key_prefix}:allowed", 0, rank, with_scores: true).last&.last || 0
|
||||
end
|
||||
|
||||
# @param [Integer] id
|
||||
# @param [Float] score
|
||||
# @param [Hash<String, Boolean>] subsets
|
||||
def add_to_and_remove_from_subsets(id, score, subsets = {})
|
||||
subsets.each_key do |subset|
|
||||
key = [key_prefix, subset].compact.join(':')
|
||||
|
||||
if score.positive? && subsets[subset]
|
||||
redis.zadd(key, score, id)
|
||||
else
|
||||
redis.zrem(key, id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def used_key(at_time)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue