From 8458c62e8ade933324fc8810646c5a649d3f70e1 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Fri, 10 Nov 2017 15:40:10 -0800 Subject: [PATCH] eliminate month scale for popular searches (takes up too much space in redis) --- app/controllers/explore/posts_controller.rb | 2 +- app/logical/popular_search_service.rb | 6 +++--- app/presenters/intro_presenter.rb | 2 +- app/presenters/post_set_presenters/post.rb | 2 +- app/views/explore/posts/searches.html.erb | 12 ++---------- 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/app/controllers/explore/posts_controller.rb b/app/controllers/explore/posts_controller.rb index d7eebb24e..e274fac03 100644 --- a/app/controllers/explore/posts_controller.rb +++ b/app/controllers/explore/posts_controller.rb @@ -10,7 +10,7 @@ module Explore def searches @date = params[:date] ? Date.parse(params[:date]) : Date.today - @search_service = PopularSearchService.new(@date, params[:scale] || "day") + @search_service = PopularSearchService.new(@date) end def missed_searches diff --git a/app/logical/popular_search_service.rb b/app/logical/popular_search_service.rb index c18c6703f..b2088081d 100644 --- a/app/logical/popular_search_service.rb +++ b/app/logical/popular_search_service.rb @@ -1,18 +1,18 @@ # queries reportbooru to find popular post searches class PopularSearchService - attr_reader :date, :scale + attr_reader :date def self.enabled? Danbooru.config.reportbooru_server.present? end - def initialize(date, scale) + def initialize(date) if !PopularSearchService.enabled? raise NotImplementedError.new("the Reportbooru service isn't configured. Popular searches are not available.") end @date = date - @scale = scale + @scale = "day" end def each_search(limit = 100, &block) diff --git a/app/presenters/intro_presenter.rb b/app/presenters/intro_presenter.rb index 2f503f122..f6fd66b7b 100644 --- a/app/presenters/intro_presenter.rb +++ b/app/presenters/intro_presenter.rb @@ -1,6 +1,6 @@ class IntroPresenter 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)) end end diff --git a/app/presenters/post_set_presenters/post.rb b/app/presenters/post_set_presenters/post.rb index 45f2140a3..1d0e43106 100644 --- a/app/presenters/post_set_presenters/post.rb +++ b/app/presenters/post_set_presenters/post.rb @@ -33,7 +33,7 @@ module PostSetPresenters def popular_tags if PopularSearchService.enabled? - PopularSearchService.new(Date.today, "day").tags.slice(0, 25) + PopularSearchService.new(Date.today).tags.slice(0, 25) else Tag.trending end diff --git a/app/views/explore/posts/searches.html.erb b/app/views/explore/posts/searches.html.erb index 303e6bba3..51ac184d3 100644 --- a/app/views/explore/posts/searches.html.erb +++ b/app/views/explore/posts/searches.html.erb @@ -20,17 +20,9 @@

- View by - <%= link_to "day", searches_explore_posts_path(:date => params[:date], :scale => "day") %> | - <%= link_to "month", searches_explore_posts_path(:date => params[:date], :scale => "month") %>. + <%= link_to "< Previous", searches_explore_posts_path(:date => 1.day.ago(@date)) %> - Back one - <%= 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]) %>. + <%= link_to "Next >", searches_explore_posts_path(:date => 1.day.since(@date)) %>