feat(platform): add the notification inbox and deterministic match search

This commit is contained in:
shira committed 2026-10-09 13:14:46 +03:00
1 parent 5edff21d2d
commit 0b11021b16
169 files changed
+17083 -443

No files matched your search

@@ -194,6 +194,17 @@ func (repository companyQuotaRepository) reserveNewCardView(
return outbound.CompanyQuotaDecision{Allowed: true}, nil
}
func (repository companyQuotaRepository) LockOrganization(ctx context.Context, organizationID uuid.UUID) error {
const location = "companyQuotaRepository.LockOrganization"
if _, err := repository.queries.LockCompanyQuotaOrganizationFirst(ctx, pgUUID(organizationID)); err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return fmt.Errorf("%s - organization was removed: %w", location, outbound.ErrCompanyQuotaSnapshotChanged)
}
return fmt.Errorf("%s - lock organization: %w", location, mapOrganizationError(err))
}
return nil
}
func (repository companyQuotaRepository) lockAndCheckSnapshot(
ctx context.Context,
location string,
@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
"lincodex/backend/internal/adapter/secondary/postgres/sqlc"
"lincodex/backend/internal/domain"
@@ -117,6 +118,80 @@ func (repository evidenceRepository) ListOrganizationFacts(
return facts, nil
}
func (repository evidenceRepository) ListOrganizationFactsBatch(
ctx context.Context,
organizationID uuid.UUID,
requests []outbound.EvidenceCandidateCategories,
) (map[uuid.UUID][]domain.EvidenceOrganizationFact, error) {
const location = "evidenceRepository.ListOrganizationFactsBatch"
if organizationID == uuid.Nil {
return nil, fmt.Errorf("%s - organization ID must be set: %w", location, domain.ErrInvalidEvidence)
}
var candidateIDs []pgtype.UUID
var pairs []string
for _, request := range requests {
if request.CandidateID == uuid.Nil {
return nil, fmt.Errorf("%s - candidate ID must be set: %w", location, domain.ErrInvalidEvidence)
}
requested, err := evidenceCategoryPairs(request.Categories)
if err != nil {
return nil, fmt.Errorf("%s - %w", location, err)
}
for _, pair := range requested {
candidateIDs = append(candidateIDs, pgUUID(request.CandidateID))
pairs = append(pairs, pair)
}
}
facts := make(map[uuid.UUID][]domain.EvidenceOrganizationFact, len(requests))
if len(pairs) == 0 {
return facts, nil
}
rows, err := repository.queries.ListOrganizationVisibleEvidenceBatch(ctx, sqlc.ListOrganizationVisibleEvidenceBatchParams{
CandidateIds: candidateIDs, Categories: pairs, OrganizationID: pgUUID(organizationID),
})
if err != nil {
return nil, fmt.Errorf("%s - select permitted facts: %w", location, markTransactionConflict(sanitizeConnectError(err)))
}
for _, row := range rows {
candidateID, err := optionalUUIDValue(row.CandidateID)
if err != nil {
return nil, fmt.Errorf("%s - %w", location, err)
}
fact, err := restoreEvidenceOrganizationFact(row.Skill, row.Grade, row.Trust, row.Basis, row.CalibrationStatus, row.ObservedYear)
if err != nil {
return nil, fmt.Errorf("%s - %w", location, err)
}
facts[candidateID] = append(facts[candidateID], fact)
}
return facts, nil
}
func (repository evidenceRepository) CountComparableRealCategories(
ctx context.Context,
categories []outbound.CategoryKey,
) (map[outbound.CategoryKey]int64, error) {
const location = "evidenceRepository.CountComparableRealCategories"
counts := make(map[outbound.CategoryKey]int64, len(categories))
if len(categories) == 0 {
return counts, nil
}
pairs := make([]string, 0, len(categories))
for _, category := range categories {
if !category.Specialization.IsKnown() || !category.Grade.IsKnown() {
return nil, fmt.Errorf("%s - category is not known: %w", location, domain.ErrInvalidEvidence)
}
pairs = append(pairs, string(category.Specialization)+"/"+string(category.Grade))
}
rows, err := repository.queries.CountRealComparableCategories(ctx, pairs)
if err != nil {
return nil, fmt.Errorf("%s - count cohorts: %w", location, markTransactionConflict(sanitizeConnectError(err)))
}
for _, row := range rows {
counts[outbound.CategoryKey{Specialization: domain.SpecializationCode(row.Specialization), Grade: domain.GradeCode(row.Grade)}] = row.Candidates
}
return counts, nil
}
func (repository evidenceRepository) ListPreviewFacts(
ctx context.Context,
candidateID uuid.UUID,
@@ -187,3 +262,10 @@ func evidenceTrust(value int16) (domain.EvidenceTrust, error) {
}
return domain.EvidenceTrust(value), nil
}
func optionalUUIDValue(value pgtype.UUID) (uuid.UUID, error) {
if !value.Valid || value.Bytes == uuid.Nil {
return uuid.Nil, fmt.Errorf("candidate identity is invalid: %w", domain.ErrInvalidEvidence)
}
return uuid.UUID(value.Bytes), nil
}
@@ -0,0 +1,94 @@
//go:build e2e
package postgres
import (
"context"
"errors"
"fmt"
"regexp"
"time"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
"lincodex/backend/internal/port/outbound"
)
// notificationFixtureEmail limits the notification fixture to the synthetic
// accounts of the isolated browser suite.
var notificationFixtureEmail = regexp.MustCompile(`@example\.test$`)
// syntheticNoticeEventType is the synthetic inbox event the fixture replays.
const syntheticNoticeEventType = "notification.synthetic_delivered"
// CheckNotificationFixtureScope accepts only a synthetic account and an
// existing organization. It is available only in e2e-tagged builds.
func CheckNotificationFixtureScope(ctx context.Context, pool *pgxpool.Pool, recipientID, organizationID uuid.UUID) error {
const location = "postgres.CheckNotificationFixtureScope"
if pool == nil || recipientID == uuid.Nil || organizationID == uuid.Nil {
return fmt.Errorf("%s - invalid fixture identity: %w", location, ErrCompanyFixtureScope)
}
var email string
err := pool.QueryRow(ctx, `SELECT email FROM users WHERE id = $1`, recipientID).Scan(&email)
if errors.Is(err, pgx.ErrNoRows) {
return fmt.Errorf("%s - recipient: %w", location, outbound.ErrUserNotFound)
}
if err != nil {
return fmt.Errorf("%s - read recipient: %w", location, sanitizedDatabaseError(err))
}
if !notificationFixtureEmail.MatchString(email) {
return fmt.Errorf("%s - recipient is outside the fixture scope: %w", location, ErrCompanyFixtureScope)
}
var exists bool
if err := pool.QueryRow(ctx, `SELECT EXISTS (SELECT 1 FROM organizations WHERE id = $1)`, organizationID).Scan(&exists); err != nil {
return fmt.Errorf("%s - read organization: %w", location, sanitizedDatabaseError(err))
}
if !exists {
return fmt.Errorf("%s - organization: %w", location, outbound.ErrOrganizationNotFound)
}
return nil
}
// NotificationFixtureEvent reads a synthetic inbox event from the outbox as
// the envelope a consumer receives for it, so the fixture can deliver it
// again the way an at-least-once bus does.
func NotificationFixtureEvent(ctx context.Context, pool *pgxpool.Pool, eventID uuid.UUID) (outbound.ConsumedEvent, error) {
const location = "postgres.NotificationFixtureEvent"
var event outbound.ConsumedEvent
var payload []byte
err := pool.QueryRow(ctx, `
SELECT event_id, event_type, schema_version, aggregate_type, aggregate_id, aggregate_version, payload::text, occurred_at
FROM outbox_events
WHERE event_id = $1 AND event_type = $2`, eventID, syntheticNoticeEventType).Scan(
&event.EventID, &event.EventType, &event.SchemaVersion, &event.AggregateType, &event.AggregateID,
&event.AggregateVersion, &payload, &event.OccurredAt)
if errors.Is(err, pgx.ErrNoRows) {
return outbound.ConsumedEvent{}, fmt.Errorf("%s - synthetic event: %w", location, outbound.ErrNotificationInboxEntryNotFound)
}
if err != nil {
return outbound.ConsumedEvent{}, fmt.Errorf("%s - read outbox event: %w", location, sanitizedDatabaseError(err))
}
event.Payload = payload
event.OccurredAt = event.OccurredAt.UTC().Truncate(time.Microsecond)
return event, nil
}
// HideNotificationFixtureOrganization records that a synthetic candidate
// hides an organization, the visibility change that removes the content of a
// synthetic notice. The browser suite cannot use the public operation for an
// organization the candidate has not seen yet.
func HideNotificationFixtureOrganization(ctx context.Context, pool *pgxpool.Pool, recipientID, organizationID uuid.UUID) error {
const location = "postgres.HideNotificationFixtureOrganization"
if err := CheckNotificationFixtureScope(ctx, pool, recipientID, organizationID); err != nil {
return err
}
if _, err := pool.Exec(ctx, `
INSERT INTO candidate_hidden_organizations (user_id, organization_id, hidden_at)
VALUES ($1, $2, now())
ON CONFLICT DO NOTHING`, recipientID, organizationID); err != nil {
return fmt.Errorf("%s - hide organization: %w", location, sanitizedDatabaseError(err))
}
return nil
}
@@ -18,9 +18,13 @@ import (
var _ outbound.NotificationInboxRepository = notificationInboxRepository{}
// notificationInboxRecipientConstraint is the foreign key of the recipient in
// migration 00032; the organization key has its own name.
const notificationInboxRecipientConstraint = "notification_inbox_events_recipient_fkey"
// NewNotificationInboxRepository creates a direct store for inbox operations.
// Transaction-bound callers can construct the same repository around the
// queries of their current UnitOfWork.
// Transaction-bound callers use UnitOfWork.NotificationInbox, which builds
// the same repository around the queries of the current transaction.
func NewNotificationInboxRepository(pool *pgxpool.Pool) outbound.NotificationInboxRepository {
return notificationInboxRepository{queries: sqlc.New(pool)}
}
@@ -29,6 +33,11 @@ type notificationInboxRepository struct {
queries *sqlc.Queries
}
// NotificationInbox binds the inbox repository to this transaction.
func (unit *UnitOfWork) NotificationInbox() outbound.NotificationInboxRepository {
return notificationInboxRepository{queries: unit.queries}
}
func (repository notificationInboxRepository) Store(
ctx context.Context,
entry domain.NotificationInboxEntry,
@@ -52,7 +61,18 @@ func (repository notificationInboxRepository) Store(
OccurredAt: pgTime(entry.OccurredAt()),
})
if err != nil {
return false, fmt.Errorf("%s - insert recipient event: %w", location, sanitizedDatabaseError(err))
sanitized := sanitizedDatabaseError(err)
var failure *databaseError
if errors.As(sanitized, &failure) && failure.code == foreignKeyViolationCode {
// The statement failed on the recipient or the organization row, so
// the surrounding transaction is aborted.
reference := outbound.ErrNotificationInboxReferenceMissing
if failure.constraint == notificationInboxRecipientConstraint {
reference = outbound.ErrNotificationInboxRecipientMissing
}
return false, fmt.Errorf("%s - insert recipient event: %w: %w", location, reference, sanitized)
}
return false, fmt.Errorf("%s - insert recipient event: %w", location, sanitized)
}
if rows == 1 {
return true, nil
@@ -116,16 +136,16 @@ func (repository notificationInboxRepository) List(
func (repository notificationInboxRepository) MarkRead(
ctx context.Context,
recipientUserID uuid.UUID,
organizationID uuid.UUID,
organizationID *uuid.UUID,
eventID uuid.UUID,
at time.Time,
) (domain.NotificationInboxEntry, error) {
const location = "notificationInboxRepository.MarkRead"
if recipientUserID == uuid.Nil || organizationID == uuid.Nil || eventID == uuid.Nil || at.IsZero() {
return domain.NotificationInboxEntry{}, fmt.Errorf("%s - recipient, organization, event, and read time are required: %w", location, domain.ErrInvalidNotificationInboxEntry)
if recipientUserID == uuid.Nil || (organizationID != nil && *organizationID == uuid.Nil) || eventID == uuid.Nil || at.IsZero() {
return domain.NotificationInboxEntry{}, fmt.Errorf("%s - recipient, event, and read time are required: %w", location, domain.ErrInvalidNotificationInboxEntry)
}
row, err := repository.queries.MarkNotificationInboxEventRead(ctx, sqlc.MarkNotificationInboxEventReadParams{
RecipientUserID: pgUUID(recipientUserID), OrganizationID: pgUUID(organizationID),
RecipientUserID: pgUUID(recipientUserID), OrganizationID: notificationInboxOptionalUUID(organizationID),
EventID: pgUUID(eventID), ReadAt: pgTime(at),
})
if errors.Is(err, pgx.ErrNoRows) {
@@ -141,6 +161,26 @@ func (repository notificationInboxRepository) MarkRead(
return entry, nil
}
func (repository notificationInboxRepository) OrganizationNameForRecipient(
ctx context.Context,
recipientUserID, organizationID uuid.UUID,
) (string, error) {
const location = "notificationInboxRepository.OrganizationNameForRecipient"
if recipientUserID == uuid.Nil || organizationID == uuid.Nil {
return "", fmt.Errorf("%s - recipient and organization are required: %w", location, domain.ErrInvalidNotificationInboxEntry)
}
name, err := repository.queries.GetNotificationOrganizationNameForRecipient(ctx, sqlc.GetNotificationOrganizationNameForRecipientParams{
RecipientUserID: pgUUID(recipientUserID), OrganizationID: pgUUID(organizationID),
})
if errors.Is(err, pgx.ErrNoRows) {
return "", fmt.Errorf("%s - read organization: %w", location, outbound.ErrNotificationInboxSourceNotVisible)
}
if err != nil {
return "", fmt.Errorf("%s - read organization: %w", location, sanitizedDatabaseError(err))
}
return name, nil
}
func validateInboxEntryForStore(entry domain.NotificationInboxEntry) error {
_, err := domain.RestoreNotificationInboxEntry(domain.NotificationInboxEntryInput{
EventID: entry.EventID(), RecipientUserID: entry.RecipientUserID(), OrganizationID: entry.OrganizationID(),
@@ -0,0 +1,56 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: candidate_search.sql
package sqlc
import (
"context"
)
const countRealComparableCategories = `-- name: CountRealComparableCategories :many
SELECT
category.specialization,
category.grade,
count(*)::bigint AS candidates
FROM candidate_assessment_categories AS category
WHERE
category.source <> 'synthetic_demo'
AND (category.specialization || '/' || category.grade) = any($1::text [])
GROUP BY category.specialization, category.grade
`
type CountRealComparableCategoriesRow struct {
Specialization string
Grade string
Candidates int64
}
// Reads that only the match search needs. The visibility of the candidates and
// their permitted evidence come from the card and evidence queries, which are
// the single copy of those barriers; this file adds no candidate-facing read.
// The number of candidates who hold each given category from a source that is
// not a synthetic demonstration, which is the size of the comparable real
// cohort that a percentile needs. It returns counts only, for the pairs the
// caller passes as "specialization/grade", and no row for a pair nobody holds.
func (q *Queries) CountRealComparableCategories(ctx context.Context, categories []string) ([]CountRealComparableCategoriesRow, error) {
rows, err := q.db.Query(ctx, countRealComparableCategories, categories)
if err != nil {
return nil, err
}
defer rows.Close()
var items []CountRealComparableCategoriesRow
for rows.Next() {
var i CountRealComparableCategoriesRow
if err := rows.Scan(&i.Specialization, &i.Grade, &i.Candidates); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
@@ -186,7 +186,6 @@ func (q *Queries) InsertCompanyInvitationQuotaUsage(ctx context.Context, arg Ins
}
const lockCompanyQuotaOrganization = `-- name: LockCompanyQuotaOrganization :one
SELECT
id,
verification_level,
@@ -204,9 +203,6 @@ type LockCompanyQuotaOrganizationRow struct {
VerificationChangedAt pgtype.Timestamptz
}
// Writers lock the organization first, then invitation/card-view state, and
// finally usage rows. The organization lock serializes quota decisions for
// the tenant and makes the subsequent count and insert atomic.
func (q *Queries) LockCompanyQuotaOrganization(ctx context.Context, organizationID pgtype.UUID) (LockCompanyQuotaOrganizationRow, error) {
row := q.db.QueryRow(ctx, lockCompanyQuotaOrganization, organizationID)
var i LockCompanyQuotaOrganizationRow
@@ -219,6 +215,32 @@ func (q *Queries) LockCompanyQuotaOrganization(ctx context.Context, organization
return i, err
}
const lockCompanyQuotaOrganizationFirst = `-- name: LockCompanyQuotaOrganizationFirst :one
SELECT id
FROM organizations
WHERE id = $1
FOR NO KEY UPDATE
`
// Writers lock the organization first, then invitation/card-view state, and
// finally usage rows. The organization lock serializes quota decisions for
// the tenant and makes the subsequent count and insert atomic.
// Takes the organization lock ahead of every share lock of a reader that will
// reserve usage later. FOR NO KEY UPDATE conflicts with itself and with FOR
// SHARE, so readers of one organization queue up instead of deadlocking on a
// share lock that each then tries to raise, but it does not conflict with the
// FOR KEY SHARE that a foreign key takes, such as the hidden-organization
// insert of a candidate, which holds the candidate's row and then needs this
// one. The reservation itself still takes FOR UPDATE inside the same
// transaction.
func (q *Queries) LockCompanyQuotaOrganizationFirst(ctx context.Context, organizationID pgtype.UUID) (pgtype.UUID, error) {
row := q.db.QueryRow(ctx, lockCompanyQuotaOrganizationFirst, organizationID)
var id pgtype.UUID
err := row.Scan(&id)
return id, err
}
const refreshCompanyCardViewQuotaUsage = `-- name: RefreshCompanyCardViewQuotaUsage :execrows
UPDATE company_card_view_quota_usage
SET
@@ -264,3 +264,93 @@ func (q *Queries) ListOrganizationVisibleEvidence(ctx context.Context, arg ListO
}
return items, nil
}
const listOrganizationVisibleEvidenceBatch = `-- name: ListOrganizationVisibleEvidenceBatch :many
SELECT DISTINCT ON (wanted.candidate_id, skill.skill_code)
wanted.candidate_id::uuid AS candidate_id,
skill.skill_code AS skill,
fact.grade,
fact.trust,
fact.basis,
fact.calibration_status,
extract(YEAR FROM fact.occurred_at AT TIME ZONE 'UTC')::integer AS observed_year
FROM (
SELECT
candidate_ids.candidate_id,
wanted_categories.category
FROM unnest($1::uuid []) WITH ORDINALITY AS candidate_ids (candidate_id, position)
INNER JOIN unnest($2::text []) WITH ORDINALITY AS wanted_categories (category, position)
ON candidate_ids.position = wanted_categories.position
) AS wanted
INNER JOIN candidate_effective_publications AS effective
ON wanted.candidate_id = effective.user_id
INNER JOIN skill_evidence_facts AS fact
ON effective.user_id = fact.candidate_id
INNER JOIN skill_evidence_skills AS skill
ON fact.id = skill.fact_id
WHERE
'categories' = any(effective.fields)
AND (skill.skill_code || '/' || fact.grade) = wanted.category
AND fact.kind = 'measurement'
AND fact.visibility = 'visible'
AND NOT EXISTS (
SELECT 1
FROM candidate_hidden_organizations AS hidden
WHERE
hidden.user_id = effective.user_id
AND hidden.organization_id = $3
)
ORDER BY wanted.candidate_id, skill.skill_code, fact.occurred_at, fact.id
`
type ListOrganizationVisibleEvidenceBatchParams struct {
CandidateIds []pgtype.UUID
Categories []string
OrganizationID pgtype.UUID
}
type ListOrganizationVisibleEvidenceBatchRow struct {
CandidateID pgtype.UUID
Skill string
Grade string
Trust int16
Basis string
CalibrationStatus string
ObservedYear int32
}
// The same organization read for a whole candidate set, so a search reads the
// evidence of every listed candidate in one statement. The pairs come from the
// caller as two parallel arrays, one row per candidate and category of the card
// that was just projected. The statement repeats every barrier of the single
// read: the effective publication view, NOT EXISTS over the candidates that
// hide the organization, the categories field, and only visible measurements.
// The candidate identifier is returned for the caller to group by and never
// leaves the server; the other columns are the same allowlist.
func (q *Queries) ListOrganizationVisibleEvidenceBatch(ctx context.Context, arg ListOrganizationVisibleEvidenceBatchParams) ([]ListOrganizationVisibleEvidenceBatchRow, error) {
rows, err := q.db.Query(ctx, listOrganizationVisibleEvidenceBatch, arg.CandidateIds, arg.Categories, arg.OrganizationID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListOrganizationVisibleEvidenceBatchRow
for rows.Next() {
var i ListOrganizationVisibleEvidenceBatchRow
if err := rows.Scan(
&i.CandidateID,
&i.Skill,
&i.Grade,
&i.Trust,
&i.Basis,
&i.CalibrationStatus,
&i.ObservedYear,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
@@ -51,6 +51,49 @@ func (q *Queries) GetNotificationInboxEvent(ctx context.Context, arg GetNotifica
return i, err
}
const getNotificationOrganizationNameForRecipient = `-- name: GetNotificationOrganizationNameForRecipient :one
SELECT organizations.name
FROM organizations
INNER JOIN users ON users.id = $1
WHERE organizations.id = $2
AND (
(
users.scenario = 'candidate'
AND NOT EXISTS (
SELECT 1 FROM candidate_hidden_organizations
WHERE candidate_hidden_organizations.user_id = users.id
AND candidate_hidden_organizations.organization_id = organizations.id
)
)
OR (
users.scenario = 'employer'
AND EXISTS (
SELECT 1 FROM memberships
WHERE memberships.user_id = users.id
AND memberships.organization_id = organizations.id
AND memberships.state = 'active'
)
)
)
`
type GetNotificationOrganizationNameForRecipientParams struct {
RecipientUserID pgtype.UUID
OrganizationID pgtype.UUID
}
// Resolve the sender organization of a synthetic notice under the recipient's
// current standing, so the notice never outlives that standing. A candidate
// sees the name only while the organization is not hidden from them; an
// employer sees it only while they are an active member. No row means the
// content is no longer visible to this recipient.
func (q *Queries) GetNotificationOrganizationNameForRecipient(ctx context.Context, arg GetNotificationOrganizationNameForRecipientParams) (string, error) {
row := q.db.QueryRow(ctx, getNotificationOrganizationNameForRecipient, arg.RecipientUserID, arg.OrganizationID)
var name string
err := row.Scan(&name)
return name, err
}
const insertNotificationInboxEvent = `-- name: InsertNotificationInboxEvent :execrows
INSERT INTO notification_inbox_events (
recipient_user_id,
@@ -183,7 +226,10 @@ const markNotificationInboxEventRead = `-- name: MarkNotificationInboxEventRead
UPDATE notification_inbox_events
SET read_at = COALESCE(read_at, $1::timestamptz)
WHERE recipient_user_id = $2
AND organization_id = $3
AND (
$3::uuid IS NULL
OR organization_id = $3::uuid
)
AND event_id = $4
RETURNING
recipient_user_id,
@@ -204,8 +250,11 @@ type MarkNotificationInboxEventReadParams struct {
EventID pgtype.UUID
}
// Persist the first read time under exact recipient and organization scope.
// Repeated calls preserve the original read timestamp.
// Persist the first read time for the recipient, optionally under one exact
// organization context. A missing organization is the candidate cabinet,
// which spans the organizations that sent to it; the employer cabinet always
// names its organization. Repeated calls preserve the original read
// timestamp.
func (q *Queries) MarkNotificationInboxEventRead(ctx context.Context, arg MarkNotificationInboxEventReadParams) (NotificationInboxEvent, error) {
row := q.db.QueryRow(ctx, markNotificationInboxEventRead,
arg.ReadAt,
@@ -131,6 +131,14 @@ type Querier interface {
// Counts the families of a category that have at least one published
// version, however many versions each has.
CountPublishedAssessmentFamilies(ctx context.Context, category string) (int32, error)
// Reads that only the match search needs. The visibility of the candidates and
// their permitted evidence come from the card and evidence queries, which are
// the single copy of those barriers; this file adds no candidate-facing read.
// The number of candidates who hold each given category from a source that is
// not a synthetic demonstration, which is the size of the comparable real
// cohort that a percentile needs. It returns counts only, for the pairs the
// caller passes as "specialization/grade", and no row for a pair nobody holds.
CountRealComparableCategories(ctx context.Context, categories []string) ([]CountRealComparableCategoriesRow, error)
// New outcomes share the generic idempotency row and are counted for the
// attempt's rolling receipt window. Replays bypass this query in the usecase.
CountRecentAssessmentSignalOutcomes(ctx context.Context, arg CountRecentAssessmentSignalOutcomesParams) (CountRecentAssessmentSignalOutcomesRow, error)
@@ -304,6 +312,12 @@ type Querier interface {
// Read the existing row after a duplicate insert so the repository can reject
// an event ID whose immutable metadata changed on redelivery.
GetNotificationInboxEvent(ctx context.Context, arg GetNotificationInboxEventParams) (NotificationInboxEvent, error)
// Resolve the sender organization of a synthetic notice under the recipient's
// current standing, so the notice never outlives that standing. A candidate
// sees the name only while the organization is not hidden from them; an
// employer sees it only while they are an active member. No row means the
// content is no longer visible to this recipient.
GetNotificationOrganizationNameForRecipient(ctx context.Context, arg GetNotificationOrganizationNameForRecipientParams) (string, error)
// Reads only the historical result. It intentionally does not join the live
// organization or membership, whose profile and state may have since changed.
GetOrganizationCreationResult(ctx context.Context, scopeHash []byte) ([]byte, error)
@@ -615,6 +629,15 @@ type Querier interface {
// calibration (the same for every candidate) say that the fact is a synthetic
// demonstration.
ListOrganizationVisibleEvidence(ctx context.Context, arg ListOrganizationVisibleEvidenceParams) ([]ListOrganizationVisibleEvidenceRow, error)
// The same organization read for a whole candidate set, so a search reads the
// evidence of every listed candidate in one statement. The pairs come from the
// caller as two parallel arrays, one row per candidate and category of the card
// that was just projected. The statement repeats every barrier of the single
// read: the effective publication view, NOT EXISTS over the candidates that
// hide the organization, the categories field, and only visible measurements.
// The candidate identifier is returned for the caller to group by and never
// leaves the server; the other columns are the same allowlist.
ListOrganizationVisibleEvidenceBatch(ctx context.Context, arg ListOrganizationVisibleEvidenceBatchParams) ([]ListOrganizationVisibleEvidenceBatchRow, error)
// Lists the organizations where an account has an active membership,
// newest membership first. The page continues after the (membership
// creation time, organization ID) position of the last item of the
@@ -678,10 +701,19 @@ type Querier interface {
// canceled, or reclaimed after the lease expired. While the lock is held,
// other workers skip the row, so the handler never runs twice at once.
LockClaimedScheduledJob(ctx context.Context, arg LockClaimedScheduledJobParams) (int64, error)
LockCompanyQuotaOrganization(ctx context.Context, organizationID pgtype.UUID) (LockCompanyQuotaOrganizationRow, error)
// Writers lock the organization first, then invitation/card-view state, and
// finally usage rows. The organization lock serializes quota decisions for
// the tenant and makes the subsequent count and insert atomic.
LockCompanyQuotaOrganization(ctx context.Context, organizationID pgtype.UUID) (LockCompanyQuotaOrganizationRow, error)
// Takes the organization lock ahead of every share lock of a reader that will
// reserve usage later. FOR NO KEY UPDATE conflicts with itself and with FOR
// SHARE, so readers of one organization queue up instead of deadlocking on a
// share lock that each then tries to raise, but it does not conflict with the
// FOR KEY SHARE that a foreign key takes, such as the hidden-organization
// insert of a candidate, which holds the candidate's row and then needs this
// one. The reservation itself still takes FOR UPDATE inside the same
// transaction.
LockCompanyQuotaOrganizationFirst(ctx context.Context, organizationID pgtype.UUID) (pgtype.UUID, error)
// Lock the current C2 before locking the publication. C2 revocation updates
// this row before it locks the publication, so preserving this order avoids
// a lock inversion and makes the current consent stable through the read.
@@ -743,8 +775,11 @@ type Querier interface {
// gate stops admitting sends until the window resets or an operator raises
// the limit. The caller holds the row lock.
MarkMailQuotaExhausted(ctx context.Context, arg MarkMailQuotaExhaustedParams) (int64, error)
// Persist the first read time under exact recipient and organization scope.
// Repeated calls preserve the original read timestamp.
// Persist the first read time for the recipient, optionally under one exact
// organization context. A missing organization is the candidate cabinet,
// which spans the organizations that sent to it; the employer cabinet always
// names its organization. Repeated calls preserve the original read
// timestamp.
MarkNotificationInboxEventRead(ctx context.Context, arg MarkNotificationInboxEventReadParams) (NotificationInboxEvent, error)
// Marks the events that the broker acknowledged. The relay passes only IDs
// whose rows its own transaction locked, so the statement never waits and the