Expand description
Dedup ledger for account-linking mails.
Keyed on the Sisu person id plus the recipient address: at send time there is no account of ours to key on, and the student number changes when a student moves between programmes. A row is written when the right to mail is claimed, before a delivery exists, so a crash between the two phases cannot mail twice.
Structs§
- Credit
Registration Account Linking Email - Existing
Linking Mail Fact - As much of one existing mail as the dedup guard and the rate caps need to decide on a person.
- Linking
Mail Failure Domain - Linking
Mail Send Status Totals - Every mail in a window, bucketed the way
crate::email_deliveries::derive_email_send_statusdoes. Computed in SQL from the same facts rather than from its output, so the two cannot drift on what counts as failed. - Linking
Mail ToQueue - A claimed slot with no delivery yet, and everything the mail needs to be written.
- NewAccount
Linking Email - Stale
Unclaimed Linking Mails - One person and course mailed to the cap without a single claim: the stale-address population, which is how “the student is ignoring us” is told from “the address Sisu holds is dead”.
Functions§
- claim_
send_ slot - Claims the right to mail this (person, course, address) once;
Nonemeans the caller must not send. Call in the transaction that mints the token, so a refused claim leaves no usable link. - claim_
send_ slots - Batched form of
claim_send_slot, keyed by token: returns thestudent_number_verification_token_idof every row actually inserted, so the caller can tell which candidates lost the race to the unique index. - claim_
unqueued - Claims slots whose mail has not been queued yet, oldest first.
- count_
send_ failed_ for_ course - Hard send failures for one course, all time. Same predicate as
get_send_status_totals_since, narrowed to a course instead of a time window. - count_
sent_ for_ person_ and_ course - How many mails this person has had for this course, tokens that expired unused included. Read against the lifetime cap when an admin asks for a resend.
- count_
sent_ since - Mails claimed in the window, whatever course they belong to. One row is one address, which is what the send-rate caps govern.
- get_
by_ course_ id_ and_ student_ number - This course’s linking mails for one student number, newest first.
- get_
by_ sisu_ person_ id - get_
existing_ facts_ for_ persons - Every live mail these people have ever been sent, any course: one query stands in for the quiet-period count, the per-course count and the dedup check of a whole batch of candidates.
- get_
latest_ by_ course_ and_ persons - This course’s newest linking mail for each of these Sisu people, keyed by person id.
- get_
send_ failure_ domains_ since - Domains behind a hard send failure in the window, worst first. Same predicate as
get_send_status_totals_since, enforced by both callingcrate::email_deliveries::is_hard_send_failurerather than each repeating the condition. - get_
send_ status_ reports - What we can honestly say about each linking mail. A slot with no delivery yet is
queued: anything else would claim a send attempt that never happened. - get_
send_ status_ totals_ since - get_
sent_ since - Mails claimed in the window, newest first, whatever course they belong to.
- get_
stale_ unclaimed - not_
handed_ over_ yet - What a claimed slot with no delivery reports. Public so a caller falling back to a default says
the same thing
get_send_status_reportswould have. - set_
email_ delivery_ id - Records which delivery carries this mail, which is also what takes the slot out of the queue.
- soft_
delete - Lets a rate-cap override or an admin resend mail the same address again.
- soft_
delete_ batch - Batch form of
soft_delete: oneUPDATEfor every row instead of one per id.