This repository has been archived on 2024-06-09. You can view files and clone it, but cannot push or open issues/pull-requests.
2018-05-11 13:20:58 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module SessionTrackingConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2022-03-01 16:48:58 +01:00
|
|
|
SESSION_UPDATE_FREQUENCY = 24.hours.freeze
|
2018-05-11 13:20:58 +02:00
|
|
|
|
|
|
|
included do
|
|
|
|
before_action :set_session_activity
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_session_activity
|
|
|
|
return unless session_needs_update?
|
2023-02-20 06:58:28 +01:00
|
|
|
|
2018-05-11 13:20:58 +02:00
|
|
|
current_session.touch
|
|
|
|
end
|
|
|
|
|
|
|
|
def session_needs_update?
|
2022-03-01 16:48:58 +01:00
|
|
|
!current_session.nil? && current_session.updated_at < SESSION_UPDATE_FREQUENCY.ago
|
2018-05-11 13:20:58 +02:00
|
|
|
end
|
|
|
|
end
|