eliminate month scale for popular searches (takes up too much space in redis)

This commit is contained in:
r888888888
2017-11-10 15:40:10 -08:00
parent 354247e3c7
commit 8458c62e8a
5 changed files with 8 additions and 16 deletions

View File

@@ -10,7 +10,7 @@ module Explore
def searches def searches
@date = params[:date] ? Date.parse(params[:date]) : Date.today @date = params[:date] ? Date.parse(params[:date]) : Date.today
@search_service = PopularSearchService.new(@date, params[:scale] || "day") @search_service = PopularSearchService.new(@date)
end end
def missed_searches def missed_searches

View File

@@ -1,18 +1,18 @@
# queries reportbooru to find popular post searches # queries reportbooru to find popular post searches
class PopularSearchService class PopularSearchService
attr_reader :date, :scale attr_reader :date
def self.enabled? def self.enabled?
Danbooru.config.reportbooru_server.present? Danbooru.config.reportbooru_server.present?
end end
def initialize(date, scale) def initialize(date)
if !PopularSearchService.enabled? if !PopularSearchService.enabled?
raise NotImplementedError.new("the Reportbooru service isn't configured. Popular searches are not available.") raise NotImplementedError.new("the Reportbooru service isn't configured. Popular searches are not available.")
end end
@date = date @date = date
@scale = scale @scale = "day"
end end
def each_search(limit = 100, &block) def each_search(limit = 100, &block)

View File

@@ -1,6 +1,6 @@
class IntroPresenter class IntroPresenter
def each def each
PopularSearchService.new(Date.today, "month").each_search(20) do |query, count| PopularSearchService.new(Date.today).each_search(20) do |query, count|
yield(query, PostSets::Intro.new(query)) yield(query, PostSets::Intro.new(query))
end end
end end

View File

@@ -33,7 +33,7 @@ module PostSetPresenters
def popular_tags def popular_tags
if PopularSearchService.enabled? if PopularSearchService.enabled?
PopularSearchService.new(Date.today, "day").tags.slice(0, 25) PopularSearchService.new(Date.today).tags.slice(0, 25)
else else
Tag.trending Tag.trending
end end

View File

@@ -20,17 +20,9 @@
</table> </table>
<p style="margin-top: 2em;"> <p style="margin-top: 2em;">
View by <%= link_to "< Previous", searches_explore_posts_path(:date => 1.day.ago(@date)) %>
<%= link_to "day", searches_explore_posts_path(:date => params[:date], :scale => "day") %> |
<%= link_to "month", searches_explore_posts_path(:date => params[:date], :scale => "month") %>.
Back one <%= link_to "Next >", searches_explore_posts_path(:date => 1.day.since(@date)) %>
<%= link_to "day", searches_explore_posts_path(:date => 1.day.ago(@date), :scale => params[:scale]) %> |
<%= link_to "month", searches_explore_posts_path(:date => 1.month.ago(@date), :scale => params[:scale]) %>.
Forward one
<%= link_to "day", searches_explore_posts_path(:date => 1.day.since(@date), :scale => params[:scale]) %> |
<%= link_to "month", searches_explore_posts_path(:date => 1.month.since(@date), :scale => params[:scale]) %>.
</p> </p>
</div> </div>
</div> </div>