2020-07-02 02:36:53 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class VerifiedSuggestions
|
|
|
|
EXPIRE_AFTER = 12.minute.seconds
|
|
|
|
MAX_ITEMS = 12
|
|
|
|
KEY = 'popularsuggestions'
|
|
|
|
|
|
|
|
class << self
|
|
|
|
include Redisable
|
|
|
|
|
|
|
|
def set(account_ids)
|
|
|
|
return if account_ids.nil? || account_ids.empty?
|
2021-01-17 22:36:20 +00:00
|
|
|
redis.with do |conn|
|
|
|
|
conn.setex(KEY, EXPIRE_AFTER, account_ids)
|
|
|
|
end
|
2020-07-02 02:36:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def get(account_id)
|
2021-01-17 22:36:20 +00:00
|
|
|
account_ids = []
|
|
|
|
redis.with do |conn|
|
|
|
|
account_ids = conn.get(KEY)
|
|
|
|
end
|
2020-07-02 02:36:53 +01:00
|
|
|
|
|
|
|
if account_ids.nil? || account_ids.empty?
|
|
|
|
account_ids = Account.searchable
|
|
|
|
.where(is_verified: true)
|
|
|
|
.discoverable
|
|
|
|
.by_recent_status
|
|
|
|
.local
|
|
|
|
.limit(MAX_ITEMS)
|
|
|
|
.pluck(:id)
|
2021-01-17 22:36:20 +00:00
|
|
|
|
2020-07-02 02:36:53 +01:00
|
|
|
set(account_ids) if account_ids.nil? || account_ids.empty?
|
|
|
|
else
|
|
|
|
account_ids = JSON.parse(account_ids)
|
|
|
|
end
|
|
|
|
|
|
|
|
return [] if account_ids.nil? || account_ids.empty?
|
|
|
|
|
|
|
|
Account.where(id: account_ids)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|