mirror of
https://github.com/discourse/discourse.git
synced 2025-02-07 20:08:26 +00:00
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:
parent
bd779834e5
commit
d1fdc66ca4
@ -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
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user