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]}
|
JSON.parse(fetch_data.to_s).map {|x| x[0]}
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_data
|
def fetch_data()
|
||||||
return [] unless self.class.enabled?
|
return [] unless self.class.enabled?
|
||||||
|
|
||||||
dates = date.strftime("%Y-%m-%d")
|
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}"
|
url = "#{Danbooru.config.reportbooru_server}/post_searches/rank?date=#{dates}"
|
||||||
response = HTTParty.get(url, Danbooru.config.httparty_options.reverse_merge(timeout: 3))
|
response = HTTParty.get(url, Danbooru.config.httparty_options.reverse_merge(timeout: 3))
|
||||||
if response.success?
|
if response.success?
|
||||||
@@ -38,6 +38,23 @@ class PopularSearchService
|
|||||||
response
|
response
|
||||||
end.to_s.force_encoding("utf-8")
|
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
|
rescue => e
|
||||||
Rails.logger.error(e.to_s)
|
Rails.logger.error(e.to_s)
|
||||||
NewRelic::Agent.notice_error(e)
|
NewRelic::Agent.notice_error(e)
|
||||||
|
|||||||
Reference in New Issue
Block a user