defer view creation on so updates are not performed when people navigate to topics

This commit is contained in:
Sam
2013-10-04 17:00:23 +10:00
parent 5bf26ec34e
commit e18b93026a
6 changed files with 49 additions and 20 deletions

View File

@ -47,8 +47,12 @@ class TopicsController < ApplicationController
# (see http://meta.discourse.org/t/noscript-tag-and-some-search-engines/8078)
return render 'topics/plain', layout: false if (SiteSetting.enable_escaped_fragments && params.has_key?('_escaped_fragment_'))
View.create_for(@topic_view.topic, request.remote_ip, current_user)
track_visit_to_topic
if should_track_visit_to_topic?
@topic_view.draft = Draft.get(current_user, @topic_view.draft_key, @topic_view.draft_sequence)
end
perform_show_response
end
@ -301,9 +305,13 @@ class TopicsController < ApplicationController
end
def track_visit_to_topic
return unless should_track_visit_to_topic?
TopicUser.track_visit! @topic_view.topic, current_user
@topic_view.draft = Draft.get(current_user, @topic_view.draft_key, @topic_view.draft_sequence)
Jobs.enqueue(:view_tracker,
topic_id: @topic_view.topic.id,
ip: request.remote_ip,
user_id: (current_user.id if current_user),
track_visit: should_track_visit_to_topic?
)
end
def should_track_visit_to_topic?