reportbooru: decrease http timeout, increase cache length.

Decrease the HTTP timeout to 0.5 seconds when fetching popular tags from
Reportbooru. Increase the length of time that popular tags are cached
from 1 minute to 1 hour. This is for the list of popular searches in the
front page sidebar.
This commit is contained in:
evazion
2020-09-14 12:53:41 -05:00
parent 5dd3027d0c
commit 0e688f8e65

View File

@@ -3,7 +3,7 @@ class ReportbooruService
def initialize(http: Danbooru::Http.new, reportbooru_server: Danbooru.config.reportbooru_server)
@reportbooru_server = reportbooru_server
@http = http
@http = http.timeout(0.5)
end
def enabled?
@@ -28,9 +28,9 @@ class ReportbooruService
request("#{reportbooru_server}/post_views/rank?date=#{date}", expires_in)
end
def popular_searches(date, limit: 100)
ranking = post_search_rankings(date)
ranking = post_search_rankings(date.yesterday) if ranking.blank?
def popular_searches(date, limit: 100, expires_in: 1.hour)
ranking = post_search_rankings(date, expires_in: expires_in)
ranking = post_search_rankings(date.yesterday, expires_in: expires_in) if ranking.blank?
ranking.take(limit).map(&:first)
end