Class: ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | activerecord/lib/active_record/middleware/database_selector/resolver/session.rb |
Overview
The session class is used by the ::ActiveRecord::Middleware::DatabaseSelector::Resolver
to save timestamps of the last write in the session.
The last_write is used to determine whether it’s safe to read from the replica or the request needs to be sent to the primary.
Class Method Summary
- .call(request)
-
.convert_time_to_timestamp(time)
Converts time to a timestamp that represents milliseconds since epoch.
-
.convert_timestamp_to_time(timestamp)
Converts milliseconds since epoch timestamp into a time object.
- .new(session) ⇒ Session constructor
Instance Attribute Summary
- #session readonly
Instance Method Summary
Constructor Details
.new(session) ⇒ Session
Class Method Details
.call(request)
[ GitHub ].convert_time_to_timestamp(time)
Converts time to a timestamp that represents milliseconds since epoch.
# File 'activerecord/lib/active_record/middleware/database_selector/resolver/session.rb', line 19
def self. (time) time.to_i * 1000 + time.usec / 1000 end
.convert_timestamp_to_time(timestamp)
Converts milliseconds since epoch timestamp into a time object.
Instance Attribute Details
#session (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/middleware/database_selector/resolver/session.rb', line 32
attr_reader :session
Instance Method Details
#last_write_timestamp
[ GitHub ]# File 'activerecord/lib/active_record/middleware/database_selector/resolver/session.rb', line 34
def self.class. (session[:last_write]) end
#save(response)
[ GitHub ]# File 'activerecord/lib/active_record/middleware/database_selector/resolver/session.rb', line 42
def save(response) end