Use the cheap Defer queue as opposed to sidekiq for view tracking.
This commit is contained in:
parent
8ff4536a08
commit
76166567fb
|
@ -365,12 +365,17 @@ class TopicsController < ApplicationController
|
|||
end
|
||||
|
||||
def track_visit_to_topic
|
||||
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?
|
||||
)
|
||||
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?
|
||||
|
||||
Scheduler::Defer.later do
|
||||
View.create_for_parent(Topic, topic_id, ip, user_id)
|
||||
if track_visit
|
||||
TopicUser.track_visit! topic_id, user_id
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
module Jobs
|
||||
|
||||
class ViewTracker < Jobs::Base
|
||||
def execute(args)
|
||||
topic_id = args[:topic_id]
|
||||
user_id = args[:user_id]
|
||||
ip = args[:ip]
|
||||
track_visit = args[:track_visit]
|
||||
|
||||
View.create_for_parent(Topic, topic_id, ip, user_id)
|
||||
if track_visit
|
||||
TopicUser.track_visit! topic_id, user_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -660,6 +660,9 @@ describe TopicsController do
|
|||
it 'shows the topic if valid api key is provided' do
|
||||
get :show, topic_id: topic.id, slug: topic.slug, api_key: api_key.key
|
||||
expect(response).to be_successful
|
||||
topic.reload
|
||||
# free test, only costs a reload
|
||||
topic.views.should == 1
|
||||
end
|
||||
|
||||
it 'returns 403 for an invalid key' do
|
||||
|
|
Loading…
Reference in New Issue