feat(platform): add the notification inbox and deterministic match search
This commit is contained in:
1 parent
5edff21d2d
commit
0b11021b16
169 files changed
+17083
-443
No files matched your search
@@ -0,0 +1,18 @@
|
||||
-- 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.
|
||||
-- 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(sqlc.arg(categories)::text [])
|
||||
GROUP BY category.specialization, category.grade;
|
||||
@@ -2,6 +2,20 @@
|
||||
-- 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.
|
||||
-- name: LockCompanyQuotaOrganizationFirst :one
|
||||
SELECT id
|
||||
FROM organizations
|
||||
WHERE id = sqlc.arg(organization_id)
|
||||
FOR NO KEY UPDATE;
|
||||
|
||||
-- name: LockCompanyQuotaOrganization :one
|
||||
SELECT
|
||||
id,
|
||||
|
||||
@@ -103,3 +103,48 @@ WHERE
|
||||
AND fact.kind = 'measurement'
|
||||
AND fact.visibility = 'visible'
|
||||
ORDER BY skill.skill_code, fact.occurred_at, fact.id;
|
||||
|
||||
-- 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.
|
||||
-- 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(sqlc.arg(candidate_ids)::uuid []) WITH ORDINALITY AS candidate_ids (candidate_id, position)
|
||||
INNER JOIN unnest(sqlc.arg(categories)::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 = sqlc.arg(organization_id)
|
||||
)
|
||||
ORDER BY wanted.candidate_id, skill.skill_code, fact.occurred_at, fact.id;
|
||||
@@ -69,13 +69,19 @@ WHERE recipient_user_id = sqlc.arg(recipient_user_id)
|
||||
ORDER BY occurred_at DESC, event_id DESC
|
||||
LIMIT sqlc.arg(page_limit);
|
||||
|
||||
-- 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.
|
||||
-- name: MarkNotificationInboxEventRead :one
|
||||
UPDATE notification_inbox_events
|
||||
SET read_at = COALESCE(read_at, sqlc.arg(read_at)::timestamptz)
|
||||
WHERE recipient_user_id = sqlc.arg(recipient_user_id)
|
||||
AND organization_id = sqlc.arg(organization_id)
|
||||
AND (
|
||||
sqlc.narg(organization_id)::uuid IS NULL
|
||||
OR organization_id = sqlc.narg(organization_id)::uuid
|
||||
)
|
||||
AND event_id = sqlc.arg(event_id)
|
||||
RETURNING
|
||||
recipient_user_id,
|
||||
@@ -87,3 +93,33 @@ RETURNING
|
||||
source_id,
|
||||
occurred_at,
|
||||
read_at;
|
||||
|
||||
-- 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.
|
||||
-- name: GetNotificationOrganizationNameForRecipient :one
|
||||
SELECT organizations.name
|
||||
FROM organizations
|
||||
INNER JOIN users ON users.id = sqlc.arg(recipient_user_id)
|
||||
WHERE organizations.id = sqlc.arg(organization_id)
|
||||
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'
|
||||
)
|
||||
)
|
||||
);
|
||||
Reference in new issue
Block a user