2019-07-02 08:10:25 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module SessionTrackingConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
UPDATE_SIGN_IN_HOURS = 24
|
|
|
|
|
|
|
|
included do
|
|
|
|
before_action :set_session_activity
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_session_activity
|
|
|
|
return unless session_needs_update?
|
2021-02-09 19:38:10 +00:00
|
|
|
ActiveRecord::Base.connected_to(role: :writing) do
|
|
|
|
conn = ActiveRecord::Base.connection
|
|
|
|
conn.exec_query "update session_activations set updated_at = NOW() where id = #{current_session.id}"
|
|
|
|
end
|
2019-07-02 08:10:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def session_needs_update?
|
2021-02-03 15:12:05 +00:00
|
|
|
!current_session.nil? && current_session.updated_at > UPDATE_SIGN_IN_HOURS.hours.ago
|
2019-07-02 08:10:25 +01:00
|
|
|
end
|
|
|
|
end
|