SuperPi.Gateway.Sessions (super_pi v0.1.0)

Copy Markdown View Source

Stored mapping from a client session id to a conversation, per principal.

The mapping is a table, so it survives a restart and is shared by every node. The unique index on (principal, session_id) decides a race between two requests (on one node or several): one creates the mapping, the other finds it and discards the conversation it had made.

Rows idle longer than config :super_pi, gateway_session_ttl_days (default 90) are deleted, and the table keeps at most gateway_session_limit rows (default 100_000), oldest first. A deleted session id starts a new conversation.

Summary

Functions

Number of stored sessions.

Returns {conversation_id, new?}. create_fun makes a conversation when the session is new.

The conversation id for a session, or nil.

Deletes expired rows and rows beyond the limit. Returns the number deleted.

Functions

count()

Number of stored sessions.

fetch_or_create(principal, session_id, create_fun)

Returns {conversation_id, new?}. create_fun makes a conversation when the session is new.

lookup(principal, session_id)

The conversation id for a session, or nil.

prune()

Deletes expired rows and rows beyond the limit. Returns the number deleted.