PERF: reduce storage requirements for incoming links

Only store incoming links for topics.
This commit is contained in:
Sam
2014-08-04 11:06:48 +10:00
parent b36273e4ac
commit 0920c4bea6
8 changed files with 129 additions and 120 deletions
@@ -24,13 +24,6 @@ describe TopicsController do
lambda { get :show, {id: topic.id} }.should_not raise_error
end
it "stores an incoming link when there is an off-site referer" do
lambda {
set_referer("http://google.com/search")
get :show, {id: topic.id}
}.should change(IncomingLink, :count).by(1)
end
describe "has_escaped_fragment?" do
render_views
@@ -92,19 +85,6 @@ describe TopicsController do
end
describe 'after inserting an incoming link' do
it 'sets last link correctly' do
set_referer("http://google.com/search")
get :show, {topic_id: topic.id}
last_link = IncomingLink.last
last_link.topic_id.should == topic.id
last_link.post_number.should == 1
end
end
describe 'set_locale' do
it 'sets the one the user prefers' do
SiteSetting.stubs(:allow_user_locale).returns(true)
@@ -590,6 +590,24 @@ describe TopicsController do
lambda { xhr :get, :show, topic_id: topic.id, slug: topic.slug }.should change(View, :count).by(1)
end
it 'records incoming links' do
user = Fabricate(:user)
get :show, topic_id: topic.id, slug: topic.slug, u: user.username
IncomingLink.count.should == 1
end
it 'records redirects' do
@request.env['HTTP_REFERER'] = 'http://twitter.com'
get :show, { id: topic.id }
@request.env['HTTP_REFERER'] = nil
get :show, topic_id: topic.id, slug: topic.slug
link = IncomingLink.first
link.referer.should == 'http://twitter.com'
end
it 'tracks a visit for all html requests' do
current_user = log_in(:coding_horror)
TopicUser.expects(:track_visit!).with(topic.id, current_user.id)