go back one day on popular search service if no results are found
This commit is contained in:
@@ -22,12 +22,12 @@ class PopularSearchService
|
||||
JSON.parse(fetch_data.to_s).map {|x| x[0]}
|
||||
end
|
||||
|
||||
def fetch_data
|
||||
def fetch_data()
|
||||
return [] unless self.class.enabled?
|
||||
|
||||
dates = date.strftime("%Y-%m-%d")
|
||||
|
||||
Cache.get("ps-day-#{dates}", 1.minute) do
|
||||
data = Cache.get("ps-day-#{dates}", 1.minute) do
|
||||
url = "#{Danbooru.config.reportbooru_server}/post_searches/rank?date=#{dates}"
|
||||
response = HTTParty.get(url, Danbooru.config.httparty_options.reverse_merge(timeout: 3))
|
||||
if response.success?
|
||||
@@ -38,6 +38,23 @@ class PopularSearchService
|
||||
response
|
||||
end.to_s.force_encoding("utf-8")
|
||||
|
||||
if data.blank?
|
||||
dates = date.yesterday.strftime("%Y-%m-%d")
|
||||
|
||||
data = Cache.get("ps-day-#{dates}", 1.minute) do
|
||||
url = "#{Danbooru.config.reportbooru_server}/post_searches/rank?date=#{dates}"
|
||||
response = HTTParty.get(url, Danbooru.config.httparty_options.reverse_merge(timeout: 3))
|
||||
if response.success?
|
||||
response = response.body
|
||||
else
|
||||
response = ""
|
||||
end
|
||||
response
|
||||
end.to_s.force_encoding("utf-8")
|
||||
end
|
||||
|
||||
data
|
||||
|
||||
rescue => e
|
||||
Rails.logger.error(e.to_s)
|
||||
NewRelic::Agent.notice_error(e)
|
||||
|
||||
Reference in New Issue
Block a user