Added verified accounts/suggestions panel, updated suggestions route
• Added: - verified accounts/suggestions panel • Updated: - suggestions route
This commit is contained in:
38
app/lib/verified_suggestions.rb
Normal file
38
app/lib/verified_suggestions.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
# 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?
|
||||
redis.setex(KEY, EXPIRE_AFTER, account_ids)
|
||||
end
|
||||
|
||||
def get(account_id)
|
||||
account_ids = redis.get(KEY)
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user