Skip to content

Add explicit opt-in stale-session cleanup - #55

Merged
dblock merged 1 commit into
mongoid:mainfrom
dblock:dblock/stale-sessions
Oct 17, 2026
Merged

dblock merged 1 commit into
mongoid:mainfrom
dblock:dblock/stale-sessions

Conversation

@dblock

@dblock dblock commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator

Fixes #37. Thanks to @jbarrantes for the original stale-session retention request.

Add MongoidStore.delete_stale_sessions(before: cutoff) and MongoStore.delete_stale_sessions(before: cutoff) through their shared base class. Require an explicit Time cutoff, bulk-delete only records whose updated_at is strictly earlier, and return the deleted count. Preserve boundary, active, missing-date and null-date records. Use the configured collection, accept UTC offsets and Rails time zones, normalize to a native UTC Time for BSON without mutating the caller, and propagate database failures. No implicit maximum age, automatic cleanup, TTL index, or change to normal request handling.

Document scheduling, deletion semantics, callback bypass, and the distinction between last-save timestamps and inactivity-based authentication expiry. Cover both adapters, repeated/empty cleanup, invalid cutoffs, custom collections, timezone handling and database-error propagation.

Both complete adapter suites pass locally on Rails 7.2 (55 Mongo / 46 Mongoid examples), using #53’s test harness against this branch’s library and specs. Branch is based independently on main. Merge #53 first to exercise the expanded matrix.

Prepared by an AI on behalf of @dblock.

@dblock
dblock force-pushed the dblock/stale-sessions branch from 2a91f00 to acc42dd Compare October 17, 2026 11:27
@dblock dblock mentioned this pull request Oct 17, 2026
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Danger Report

No issues found.

View run

Require a Time cutoff and delete only sessions whose updated_at precedes it, returning the count from the configured collection. Normalize timezone-aware cutoffs to native UTC Time for BSON without mutating the caller. Leave retention policy and scheduling to the caller; install no defaults, background jobs, or TTL indexes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dblock
dblock force-pushed the dblock/stale-sessions branch from acc42dd to a789ac7 Compare October 17, 2026 11:40
@dblock
dblock merged commit 7248d6a into mongoid:main Oct 17, 2026
26 checks passed
@dblock
dblock deleted the dblock/stale-sessions branch October 17, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Delete stale sessions

1 participant