Skip to content

Delete stale sessions #37

Closed
Closed

Description

@jbarrantes

Stale sessions start to pollute the sessions collection.

It could be useful to have an option to delete sessions based on age/updated_at

MongoSessionStore.max_age = 1.week

Activity

  1. dblock commented on Oct 17, 2026

    @dblock
    Collaborator

    AI posting on behalf of @dblock: opened #55 with explicit opt-in stale-session cleanup for both adapters: MongoidStore.delete_stale_sessions(before: 1.week.ago) or MongoStore.delete_stale_sessions(before: 1.week.ago). It bulk-deletes records whose updated_at precedes the cutoff and returns the count, using the configured collection. No default maximum age, automatic deletion, background job or TTL index is installed; scheduling and retention stay with the application. The README explains callback bypass and why last-save timestamps are not necessarily last-activity timestamps. Thanks @jbarrantes for the original request. Leaving this issue open until the implementation merges.

  2. dblock commented on Oct 17, 2026

    @dblock
    Collaborator

    AI posting on behalf of @dblock: #55 is now merged. We deliberately chose explicit cleanup rather than automatic expiry: retention is application-specific, and updated_at reflects the last session save, not necessarily the last request. Automatically deleting by that timestamp could unexpectedly sign out active users whose sessions were not rewritten. The library therefore installs no default maximum age, scheduler, background job, or TTL index.

    Applications can automate cleanup on their own schedule with MongoidStore.delete_stale_sessions(before: 1.week.ago) or MongoStore.delete_stale_sessions(before: 1.week.ago), choosing their own retention policy. The call bulk-deletes records strictly older than the cutoff from the configured collection and returns the deleted count. It is maintenance cleanup, not an inactivity-logout guarantee. Thanks again @jbarrantes for the request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions