diff --git a/app/models/tag.rb b/app/models/tag.rb index 25ac8e179..e2d4098e1 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -205,45 +205,6 @@ class Tag < ApplicationRecord end end - module StatisticsMethods - def trending_count_limit - 10 - end - - def trending - Cache.get("popular-tags-v3", 1.hour) do - CurrentUser.scoped(User.admins.first, "127.0.0.1") do - n = 24 - counts = {} - - while counts.empty? && n < 1000 - tag_strings = Post.select_values_sql("select tag_string from posts where created_at >= ?", n.hours.ago) - tag_strings.each do |tag_string| - tag_string.split.each do |tag| - counts[tag] ||= 0 - counts[tag] += 1 - end - end - n *= 2 - end - - counts = counts.to_a.select {|x| x[1] > trending_count_limit} - counts = counts.map do |tag_name, recent_count| - tag = Tag.find_or_create_by_name(tag_name) - if tag.category == Tag.categories.artist - # we're not interested in artists in the trending list - [tag_name, 0] - else - [tag_name, recent_count.to_f / tag.post_count.to_f] - end - end - - counts.sort_by {|x| -x[1]}.slice(0, 25).map(&:first) - end - end - end - end - concerning :NameMethods do def unqualified_name name.gsub(/_\(.*\)\z/, "").tr("_", " ") @@ -956,7 +917,6 @@ class Tag < ApplicationRecord include ApiMethods include CountMethods include CategoryMethods - extend StatisticsMethods extend ParseMethods extend SearchMethods end diff --git a/app/presenters/post_set_presenters/post.rb b/app/presenters/post_set_presenters/post.rb index 082cf95e4..b6406348c 100644 --- a/app/presenters/post_set_presenters/post.rb +++ b/app/presenters/post_set_presenters/post.rb @@ -35,7 +35,7 @@ module PostSetPresenters if PopularSearchService.enabled? PopularSearchService.new(Date.today).tags else - Tag.trending + frequent_tags end end diff --git a/test/unit/tag_test.rb b/test/unit/tag_test.rb index 9af0700bc..83022be57 100644 --- a/test/unit/tag_test.rb +++ b/test/unit/tag_test.rb @@ -12,24 +12,6 @@ class TagTest < ActiveSupport::TestCase CurrentUser.ip_addr = nil end - context ".trending" do - setup do - Tag.stubs(:trending_count_limit).returns(0) - - travel_to(1.week.ago) do - FactoryBot.create(:post, :tag_string => "aaa") - FactoryBot.create(:post, :tag_string => "bbb") - end - - FactoryBot.create(:post, :tag_string => "bbb") - FactoryBot.create(:post, :tag_string => "ccc") - end - - should "order the results by the total post count" do - assert_equal(["ccc", "bbb"], Tag.trending) - end - end - context "A tag category fetcher" do should "fetch for a single tag" do FactoryBot.create(:artist_tag, :name => "test")