Fix #4522: Sidebar doesn't show most searched tags at certain times of day.
Revert back to previous workaround of fetching previous day if current day returns no result. A terrible hack, really we should convert dates to Reportbooru's timezone, but that has other complications.
This commit is contained in:
@@ -28,11 +28,11 @@ module Explore
|
||||
|
||||
def searches
|
||||
@date, @scale, @min_date, @max_date = parse_date(params)
|
||||
@search_service = ReportbooruService.new
|
||||
@searches = ReportbooruService.new.popular_searches(@date)
|
||||
end
|
||||
|
||||
def missed_searches
|
||||
@search_service = ReportbooruService.new
|
||||
@missed_searches = ReportbooruService.new.missed_search_rankings
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -20,29 +20,30 @@ class ReportbooruService
|
||||
body.lines.map(&:split).map { [_1, _2.to_i] }
|
||||
end
|
||||
|
||||
def post_search_rankings(date = Date.today, expires_in: 1.minutes)
|
||||
return [] unless enabled?
|
||||
|
||||
response = http.cache(expires_in).get("#{reportbooru_server}/post_searches/rank?date=#{date}")
|
||||
return [] if response.status != 200
|
||||
JSON.parse(response.to_s.force_encoding("utf-8"))
|
||||
def post_search_rankings(date, expires_in: 1.minutes)
|
||||
request("#{reportbooru_server}/post_searches/rank?date=#{date}", expires_in)
|
||||
end
|
||||
|
||||
def post_view_rankings(date = Date.today, expires_in: 1.minutes)
|
||||
return [] unless enabled?
|
||||
|
||||
response = http.cache(expires_in).get("#{reportbooru_server}/post_views/rank?date=#{date}")
|
||||
return [] if response.status != 200
|
||||
JSON.parse(response.to_s.force_encoding("utf-8"))
|
||||
def post_view_rankings(date, expires_in: 1.minutes)
|
||||
request("#{reportbooru_server}/post_views/rank?date=#{date}", expires_in)
|
||||
end
|
||||
|
||||
def popular_searches(date = Date.today, limit: 100)
|
||||
def popular_searches(date, limit: 100)
|
||||
ranking = post_search_rankings(date)
|
||||
ranking.take(limit).map(&:first)
|
||||
end
|
||||
|
||||
def popular_posts(date = Date.today, limit: 100)
|
||||
def popular_posts(date, limit: 100)
|
||||
ranking = post_view_rankings(date)
|
||||
ranking = post_view_rankings(date.yesterday) if ranking.blank?
|
||||
ranking.take(limit).map { |x| Post.find(x[0]) }
|
||||
end
|
||||
|
||||
def request(url, expires_in)
|
||||
return [] unless enabled?
|
||||
|
||||
response = http.cache(expires_in).get(url)
|
||||
return [] if response.status != 200
|
||||
JSON.parse(response.to_s.force_encoding("utf-8"))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @search_service.missed_search_rankings.each do |tags, count| %>
|
||||
<% @missed_searches.each do |tags, count| %>
|
||||
<tr class="tag-type-<%= Tag.category_for(tags) %>">
|
||||
<td><%= link_to tags, posts_path(:tags => tags) %></td>
|
||||
<td>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @search_service.post_search_rankings(@date).each do |tags, count| %>
|
||||
<% @searches.each do |tags, count| %>
|
||||
<tr class="tag-type-<%= Tag.category_for(tags) %>">
|
||||
<td><%= link_to tags, posts_path(:tags => tags) %></td>
|
||||
<td style="text-align: right;"><%= count.to_i %></td>
|
||||
|
||||
Reference in New Issue
Block a user