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. A row holds its address only while its link can still be used; once the link has expired or been used, a later mail to the address replaces it.
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
Email List Row - One linking email as the admin’s searchable list shows it.
- 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”.
- Unused
Linking Link - A linking email whose link can still be used.
Enums§
- Linking
Email List Status - Which linking emails a
get_pagelists, by what became of their link and their send. - Linking
Mail Link State - Whether the link a linking mail carries can still be opened.
Functions§
- backdate
- Moves a mail’s
sent_atageinto the past, for seeding mails sent before today. - claim_
send_ slot - Claims the right to mail this (person, course, address);
Nonemeans another row holds the address and 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_
mails_ per_ person_ for_ course - How many linking mails one course has sent each of these people, replaced ones included.
- 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, replaced ones 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.
- count_
unused_ links_ by_ course_ code - How many links can still be used per course code, over every course with a module on the code.
- 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_
link_ states - The state of each mail’s link, by mail id.
- get_
page - A page of linking emails on live courses, newest first, including ones a later mail replaced.
- 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_
stale_ unclaimed - get_
unused_ links - Linking emails whose link can still be used, oldest first.
- 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. - replace_
lapsed_ slots - Marks the rows these new slots would collide with in the dedup key as replaced, where their link can no longer be used, so the slots can be claimed. Rows holding their address are left alone.
- retire_
unused_ for_ link - Voids the unused links in the mails about the person behind a verified link, and marks those mails replaced, so that once unlinked the person can be mailed again. The mails still count against the caps.
- 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.