NAME
Mojo::ATProto::OAuth::SessionStore::Pg - Postgres-backed session store for Mojo::ATProto::OAuth
SYNOPSIS
my $oauth = Mojo::ATProto::OAuth->new(..., store => [Pg => 'postgresql://user:pass@host/dbname']);
DESCRIPTION
Implements the full store interface described in "THE STORE INTERFACE" in Mojo::ATProto::OAuth on top of Mojo::Pg. Constructor arguments are passed straight to Mojo::Pg->new; the schema is created and migrated automatically.
Session locking
lock_session/lock_session_p (which "refresh_tokens" in Mojo::ATProto::OAuth runs under) take a transaction-scoped advisory lock (pg_advisory_xact_lock) keyed on the session's (account_did, session_id), on a dedicated connection. That lock excludes every other process using the same database, waits without polling (the async form doesn't block the event loop while it waits), and is released when the code finishes, fails, or the connection drops. It doesn't lock the sessions row itself, so ordinary reads and writes of the session carry on while it's held.
The locking connection sits idle in a transaction while the lock is held (for the length of one auth-server round trip), so a server-side idle_in_transaction_session_timeout shorter than that will abort the refresh, and each concurrently held lock uses one connection from the pool.
ATTRIBUTES
pg
The underlying Mojo::Pg instance.
SEE ALSO
Mojo::ATProto::OAuth, Mojo::ATProto::OAuth::SessionStore::SQLite