Skip to content

Add last_request_at_update_interval option to Timeoutable - #5857

Open
albertski wants to merge 1 commit into
heartcombo:mainfrom
albertski:add-session-update-interval
Open

Add last_request_at_update_interval option to Timeoutable#5857
albertski wants to merge 1 commit into
heartcombo:mainfrom
albertski:add-session-update-interval

Conversation

@albertski

Copy link
Copy Markdown

Adds a last_request_at_update_interval configuration option to the :timeoutable module. When set, last_request_at is only written to the session if the specified interval has elapsed since the last write, reducing unnecessary database writes on high-traffic applications.

Usage

# config/initializers/devise.rb
config.last_request_at_update_interval = 1.minute

The interval must be set to a value less than timeout_in to avoid users being timed out prematurely.

Motivation

A recent optimization in activerecord-session_store (#166) aimed to avoid unnecessary database writes by skipping session saves when the data had not changed. The intention of this optimization is valid. There is no reason to write to the database on every request, particularly when making frequent API or GraphQL calls.

That optimization introduced a bug (#236) where in-place mutations to session data were silently dropped, which I addressed in (#238).

This PR allows applications that use Timeoutable to take advantage of the optimizations.

When set, last_request_at is only updated if more than session_update_interval has elapsed since the last write
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant