Skip to main content

Module credit_registration_account_linking_emails

Module credit_registration_account_linking_emails 

Source
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§

CreditRegistrationAccountLinkingEmail
ExistingLinkingMailFact
As much of one existing mail as the dedup guard and the rate caps need to decide on a person.
LinkingEmailListRow
One linking email as the admin’s searchable list shows it.
LinkingMailFailureDomain
LinkingMailSendStatusTotals
Every mail in a window, bucketed the way crate::email_deliveries::derive_email_send_status does. Computed in SQL from the same facts rather than from its output, so the two cannot drift on what counts as failed.
LinkingMailToQueue
A claimed slot with no delivery yet, and everything the mail needs to be written.
NewAccountLinkingEmail
StaleUnclaimedLinkingMails
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”.
UnusedLinkingLink
A linking email whose link can still be used.

Enums§

LinkingEmailListStatus
Which linking emails a get_page lists, by what became of their link and their send.
LinkingMailLinkState
Whether the link a linking mail carries can still be opened.

Functions§

backdate
Moves a mail’s sent_at age into the past, for seeding mails sent before today.
claim_send_slot
Claims the right to mail this (person, course, address); None means 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 the student_number_verification_token_id of 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 calling crate::email_deliveries::is_hard_send_failure rather 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_reports would 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: one UPDATE for every row instead of one per id.