pub async fn create_idempotent(
pool: &PgPool,
actor: &Actor,
input: NewItem,
key: &str,
payload_hash: &str,
) -> AppResult<(Revision, bool)>Expand description
create with an idempotency key: the first request with a key creates
the item; a repetition by the same user with the same payload_hash
returns that item (second value true, nothing is created); the same key
with another payload is a conflict (409).
§Invariants
- Permission / locks / audit / data: as
create; a replay is a read: the original revision is returned only while the actor may read it. - Atomic: the key row is inserted first, in the creation’s transaction. Two simultaneous requests with one key meet at the primary key: the second waits for the first to commit (replay) or roll back (it then creates the item itself), so exactly one item exists. A refused or failed creation leaves no key behind.