2018-05-11 20:20:58 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module SessionTrackingConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2022-03-02 00:48:58 +09:00
|
|
|
SESSION_UPDATE_FREQUENCY = 24.hours.freeze
|
2018-05-11 20:20:58 +09:00
|
|
|
|
|
|
|
included do
|
|
|
|
before_action :set_session_activity
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_session_activity
|
|
|
|
return unless session_needs_update?
|
2023-02-20 14:58:28 +09:00
|
|
|
|
2018-05-11 20:20:58 +09:00
|
|
|
current_session.touch
|
|
|
|
end
|
|
|
|
|
|
|
|
def session_needs_update?
|
2022-03-02 00:48:58 +09:00
|
|
|
!current_session.nil? && current_session.updated_at < SESSION_UPDATE_FREQUENCY.ago
|
2018-05-11 20:20:58 +09:00
|
|
|
end
|
|
|
|
end
|