Updated PopularLinksController
• Updated: - PopularLinksController
This commit is contained in:
parent
0ac93cceec
commit
10219345f7
|
@ -20,14 +20,18 @@ class Api::V1::PopularLinksController < Api::BaseController
|
||||||
|
|
||||||
def get_top_gab
|
def get_top_gab
|
||||||
# prod gab.com @gab account = 251
|
# prod gab.com @gab account = 251
|
||||||
Status.where(account_id: '1').limit(2)
|
Status.where(account_id: '251').limit(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_videos
|
def get_videos
|
||||||
|
return []
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_cards
|
def get_cards
|
||||||
statusIds = Status.where('statuses.created_at > ?', 24.hours.ago)
|
body = Redis.current.get("popular_links:card_ids")
|
||||||
|
|
||||||
|
if body.nil? || body.empty?
|
||||||
|
statusIds = Status.where('statuses.created_at > ?', 24.hours.ago)
|
||||||
.joins(:status_stat)
|
.joins(:status_stat)
|
||||||
.order('status_stats.favourites_count DESC')
|
.order('status_stats.favourites_count DESC')
|
||||||
.where('status_stats.favourites_count > 1')
|
.where('status_stats.favourites_count > 1')
|
||||||
|
@ -36,24 +40,26 @@ class Api::V1::PopularLinksController < Api::BaseController
|
||||||
.limit(100)
|
.limit(100)
|
||||||
.pluck('statuses.id')
|
.pluck('statuses.id')
|
||||||
|
|
||||||
cards = PreviewCard.joins("LEFT JOIN preview_cards_statuses ON preview_cards.id = preview_cards_statuses.preview_card_id")
|
cards = PreviewCard.joins("LEFT JOIN preview_cards_statuses ON preview_cards.id = preview_cards_statuses.preview_card_id")
|
||||||
.where('preview_cards_statuses.preview_card_id IS NOT NULL')
|
.where('preview_cards_statuses.preview_card_id IS NOT NULL')
|
||||||
.where('preview_cards_statuses.status_id IN (?)', statusIds)
|
.where('preview_cards_statuses.status_id IN (?)', statusIds)
|
||||||
.having('COUNT(preview_cards_statuses.preview_card_id) > 1')
|
.having('COUNT(preview_cards_statuses.preview_card_id) > 1')
|
||||||
.where('preview_cards.updated_at > ?', 24.hours.ago)
|
.where('preview_cards.updated_at > ?', 24.hours.ago)
|
||||||
.order('COUNT(preview_cards_statuses.preview_card_id) DESC')
|
.order('COUNT(preview_cards_statuses.preview_card_id) DESC')
|
||||||
.group('preview_cards.id')
|
.group('preview_cards.id')
|
||||||
.limit(10)
|
.limit(10)
|
||||||
|
|
||||||
|
card_ids = cards.map(&:id)
|
||||||
|
|
||||||
|
Redis.current.set("popular_links:card_ids", card_ids.join(','))
|
||||||
|
Redis.current.expire("popular_links:card_ids", 15.minutes.seconds)
|
||||||
|
|
||||||
|
return cards
|
||||||
|
else
|
||||||
|
cards = PreviewCard.where(id: body.split(','))
|
||||||
|
return cards
|
||||||
|
end
|
||||||
|
|
||||||
cards
|
|
||||||
|
|
||||||
# if body.nil? || body.empty?
|
|
||||||
# Redis.current.set("gabtrends:feed", body)
|
|
||||||
# Redis.current.expire("gabtrends:feed", 1.hour.seconds)
|
|
||||||
# return cards
|
|
||||||
# else
|
|
||||||
# return cardIds
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue