Skip to content

A platform for community discussion. Free, open, simple.

FIX: do not show links with 0 click on topic map

Arpit Jalan7da22e395bf0
diff --git a/app/models/topic_link.rb b/app/models/topic_link.rb
index c7a745218d1..b89cede20b7 100644
--- a/app/models/topic_link.rb
+++ b/app/models/topic_link.rb
@@ -61,6 +61,8 @@ SQL
# note that ILIKE means "case insensitive LIKE"
builder.where("NOT(ftl.url ILIKE '%.png' OR ftl.url ILIKE '%.jpg' OR ftl.url ILIKE '%.gif')")
builder.where("COALESCE(ft.archetype, 'regular') <> :archetype", archetype: Archetype.private_message)
+ # do not show links with 0 click
+ builder.where("clicks > 0")
builder.secure_category(guardian.secure_category_ids)
diff --git a/spec/models/topic_link_spec.rb b/spec/models/topic_link_spec.rb
index d3d53a07280..165239cd6e5 100644
--- a/spec/models/topic_link_spec.rb
+++ b/spec/models/topic_link_spec.rb
@@ -321,16 +321,20 @@ http://b.com/#{'a' * 500}
it 'has the correct results' do
TopicLink.extract_from(post)
- topic_link = post.topic.topic_links.first
- TopicLinkClick.create(topic_link: topic_link, ip_address: '192.168.1.1')
+ topic_link_first = post.topic.topic_links.first
+ TopicLinkClick.create!(topic_link: topic_link_first, ip_address: '192.168.1.1')
+ TopicLinkClick.create!(topic_link: topic_link_first, ip_address: '192.168.1.2')
+ topic_link_second = post.topic.topic_links.second
+ TopicLinkClick.create!(topic_link: topic_link_second, ip_address: '192.168.1.1')
expect(counts_for[post.id]).to be_present
- expect(counts_for[post.id].find { |l| l[:url] == 'http://google.com' }[:clicks]).to eq(0)
- expect(counts_for[post.id].first[:clicks]).to eq(1)
+ expect(counts_for[post.id].first[:clicks]).to eq(2)
+ expect(counts_for[post.id].second[:clicks]).to eq(1)
array = TopicLink.topic_map(Guardian.new, post.topic_id)
- expect(array.length).to eq(6)
- expect(array[0].clicks).to eq(1)
+ expect(array.length).to eq(2)
+ expect(array[0].clicks).to eq(2)
+ expect(array[1].clicks).to eq(1)
end
it 'secures internal links correctly' do
@@ -340,6 +344,7 @@ http://b.com/#{'a' * 500}
url = "http://#{test_uri.host}/t/topic-slug/#{secret_topic.id}"
post = Fabricate(:post, raw: "hello test topic #{url}")
TopicLink.extract_from(post)
+ TopicLinkClick.create!(topic_link: post.topic.topic_links.first, ip_address: '192.168.1.1')
expect(TopicLink.topic_map(Guardian.new, post.topic_id).count).to eq(1)
expect(TopicLink.counts_for(Guardian.new, post.topic, [post]).length).to eq(1)