FIX: For spam detection, don't count total occurances of links of the same host, but

post count including that host.
This commit is contained in:
Robin Ward 2013-05-24 15:20:58 -04:00
parent bd779834e5
commit d1fdc66ca4
2 changed files with 7 additions and 5 deletions

View File

@ -179,7 +179,7 @@ class Post < ActiveRecord::Base
raw_links.each do |u| raw_links.each do |u|
uri = URI.parse(u) uri = URI.parse(u)
host = uri.host host = uri.host
@linked_hosts[host] = (@linked_hosts[host] || 0) + 1 @linked_hosts[host] ||= 1
end end
@linked_hosts @linked_hosts
end end
@ -187,9 +187,11 @@ class Post < ActiveRecord::Base
def total_hosts_usage def total_hosts_usage
hosts = linked_hosts.clone hosts = linked_hosts.clone
# Count hosts in previous posts the user has made, PLUS these new ones TopicLink.where(domain: hosts.keys, user_id: acting_user.id)
TopicLink.where(domain: hosts.keys, user_id: acting_user.id).each do |tl| .group(:domain, :post_id)
hosts[tl.domain] = (hosts[tl.domain] || 0) + 1 .count.keys.each do |tuple|
domain = tuple[0]
hosts[domain] = (hosts[domain] || 0) + 1
end end
hosts hosts

View File

@ -201,7 +201,7 @@ describe Post do
end end
it "it counts properly with more than one link on the same host" do it "it counts properly with more than one link on the same host" do
three_links.linked_hosts.should == {"discourse.org" => 2, "www.imdb.com" => 1} three_links.linked_hosts.should == {"discourse.org" => 1, "www.imdb.com" => 1}
end end
end end