remove post view counts, add search counts

This commit is contained in:
r888888888
2015-07-27 17:21:17 -07:00
parent fdc62b0e07
commit f87c71cf23
14 changed files with 93 additions and 170 deletions

View File

@@ -0,0 +1,31 @@
# queries reportbooru to find popular post searches
class PopularSearchService
attr_reader :date, :scale
def initialize(date, scale)
@date = date
@scale = scale
end
def each_search(&block)
fetch_data.scan(/\S+/).in_groups_of(2).each(&block)
end
def fetch_data
dates = date.strftime("%Y-%m-%d")
Cache.get("ps-#{scale}-#{dates}", 1.minute) do
url = URI.parse("#{Danbooru.config.report_server}/hits/#{scale}?date=#{dates}")
response = []
Net::HTTP.start(url.host, url.port, :use_ssl => url.is_a?(URI::HTTPS)) do |http|
http.read_timeout = 1
http.request_get(url.request_uri) do |res|
if res.is_a?(Net::HTTPSuccess)
response = res.body
end
end
end
response
end
end
end