tags: remove Tag.trending method.
This is used for the frontpage taglist when popular searches are disabled. This isn't used in production and there's no need for it in development.
This commit is contained in:
@@ -205,45 +205,6 @@ class Tag < ApplicationRecord
|
|||||||
end
|
end
|
||||||
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
|
concerning :NameMethods do
|
||||||
def unqualified_name
|
def unqualified_name
|
||||||
name.gsub(/_\(.*\)\z/, "").tr("_", " ")
|
name.gsub(/_\(.*\)\z/, "").tr("_", " ")
|
||||||
@@ -956,7 +917,6 @@ class Tag < ApplicationRecord
|
|||||||
include ApiMethods
|
include ApiMethods
|
||||||
include CountMethods
|
include CountMethods
|
||||||
include CategoryMethods
|
include CategoryMethods
|
||||||
extend StatisticsMethods
|
|
||||||
extend ParseMethods
|
extend ParseMethods
|
||||||
extend SearchMethods
|
extend SearchMethods
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ module PostSetPresenters
|
|||||||
if PopularSearchService.enabled?
|
if PopularSearchService.enabled?
|
||||||
PopularSearchService.new(Date.today).tags
|
PopularSearchService.new(Date.today).tags
|
||||||
else
|
else
|
||||||
Tag.trending
|
frequent_tags
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -12,24 +12,6 @@ class TagTest < ActiveSupport::TestCase
|
|||||||
CurrentUser.ip_addr = nil
|
CurrentUser.ip_addr = nil
|
||||||
end
|
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
|
context "A tag category fetcher" do
|
||||||
should "fetch for a single tag" do
|
should "fetch for a single tag" do
|
||||||
FactoryBot.create(:artist_tag, :name => "test")
|
FactoryBot.create(:artist_tag, :name => "test")
|
||||||
|
|||||||
Reference in New Issue
Block a user