Class: ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
- Defined in:
- activerecord/lib/active_record/middleware/database_selector/resolver/session.rb
Overview
The session class is used by the 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.
Instance Attribute Summary collapse
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Class Method Summary collapse
- .call(request) ⇒ Object
-
.convert_time_to_timestamp(time) ⇒ Object
Converts time to a timestamp that represents milliseconds since epoch.
-
.convert_timestamp_to_time(timestamp) ⇒ Object
Converts milliseconds since epoch timestamp into a time object.
Instance Method Summary collapse
-
#initialize(session) ⇒ Session
constructor
A new instance of Session.
- #last_write_timestamp ⇒ Object
- #save(response) ⇒ Object
- #update_last_write_timestamp ⇒ Object
Constructor Details
#initialize(session) ⇒ Session
Returns a new instance of Session.
28 29 30 |
# File 'activerecord/lib/active_record/middleware/database_selector/resolver/session.rb', line 28 def initialize(session) @session = session end |
Instance Attribute Details
#session ⇒ Object (readonly)
Returns the value of attribute session
32 33 34 |
# File 'activerecord/lib/active_record/middleware/database_selector/resolver/session.rb', line 32 def session @session end |
Class Method Details
.call(request) ⇒ Object
13 14 15 |
# File 'activerecord/lib/active_record/middleware/database_selector/resolver/session.rb', line 13 def self.call(request) new(request.session) end |
.convert_time_to_timestamp(time) ⇒ Object
Converts time to a timestamp that represents milliseconds since epoch.
19 20 21 |
# File 'activerecord/lib/active_record/middleware/database_selector/resolver/session.rb', line 19 def self.(time) time.to_i * 1000 + time.usec / 1000 end |
Instance Method Details
#last_write_timestamp ⇒ Object
34 35 36 |
# File 'activerecord/lib/active_record/middleware/database_selector/resolver/session.rb', line 34 def self.class.(session[:last_write]) end |
#save(response) ⇒ Object
42 43 |
# File 'activerecord/lib/active_record/middleware/database_selector/resolver/session.rb', line 42 def save(response) end |