From 26280368f7bf04d89591e34513af8f55259b6440 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 11 Aug 2015 12:21:16 -0700 Subject: [PATCH] change intro explorer to use popular searches --- app/logical/popular_search_service.rb | 4 ++-- app/presenters/intro_presenter.rb | 8 ++------ app/views/explore/posts/intro.html.erb | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/logical/popular_search_service.rb b/app/logical/popular_search_service.rb index fe8517c68..27d44ae25 100644 --- a/app/logical/popular_search_service.rb +++ b/app/logical/popular_search_service.rb @@ -7,8 +7,8 @@ class PopularSearchService @scale = scale end - def each_search(&block) - fetch_data.scan(/(.+?) (\d+)\.0\n/).each(&block) + def each_search(&block, limit = 100) + fetch_data.scan(/(.+?) (\d+)\.0\n/).slice(0, limit).each(&block) end def fetch_data diff --git a/app/presenters/intro_presenter.rb b/app/presenters/intro_presenter.rb index 0d55da535..83e73c0d1 100644 --- a/app/presenters/intro_presenter.rb +++ b/app/presenters/intro_presenter.rb @@ -1,11 +1,7 @@ class IntroPresenter - def popular_tags - Tag.where("category = 3").order("post_count desc").limit(8).map(&:name) - end - def each - popular_tags.each do |tag| - yield(tag, PostSets::Intro.new(tag)) + PopularSearchService.new(Date.today, "week").each_search(20) do |query, count| + yield(query, PostSets::Intro.new(query)) end end end diff --git a/app/views/explore/posts/intro.html.erb b/app/views/explore/posts/intro.html.erb index 09269a0b3..aa8c4c5f2 100644 --- a/app/views/explore/posts/intro.html.erb +++ b/app/views/explore/posts/intro.html.erb @@ -10,7 +10,7 @@ <% end %> -

Type in your favorite anime, manga, or character (last name first). Here are some examples:

+

Type in your favorite anime, manga, or character (last name first). Here are some popular examples:

<% cache("intro-page", :expires_in => 1.hour) do %> <% @presenter.each do |tag, post_set| %>