class ActiveRecord::Middleware::DatabaseSelector::Resolver::Session

:nodoc:
from the replica or the request needs to be sent to the primary.
The last_write is used to determine whether it’s safe to read
timestamps of the last write in the session.
The session class is used by the DatabaseSelector::Resolver to save

def self.call(request)

:nodoc:
from the replica or the request needs to be sent to the primary.
The last_write is used to determine whether it's safe to read

timestamps of the last write in the session.
The session class is used by the DatabaseSelector::Resolver to save
def self.call(request)
  new(request.session)
end

def self.convert_time_to_timestamp(time)

epoch.
Converts time to a timestamp that represents milliseconds since
def self.convert_time_to_timestamp(time)
  time.to_i * 1000 + time.usec / 1000
end

def self.convert_timestamp_to_time(timestamp)

Converts milliseconds since epoch timestamp into a time object.
def self.convert_timestamp_to_time(timestamp)
  timestamp ? Time.at(timestamp / 1000, (timestamp % 1000) * 1000) : Time.at(0)
end

def initialize(session)

def initialize(session)
  @session = session
end

def last_write_timestamp

def last_write_timestamp
  self.class.convert_timestamp_to_time(session[:last_write])
end

def save(response)

def save(response)
end

def update_last_write_timestamp

def update_last_write_timestamp
  session[:last_write] = self.class.convert_time_to_timestamp(Time.now)
end