feat(db): add similarity lookup queries (ListActiveContextualLikesForUser, GetCurrentSessionVectorForUser)
This commit is contained in:
@@ -8,3 +8,14 @@ VALUES ($1, $2, $3, $4);
|
||||
UPDATE contextual_likes
|
||||
SET deleted_at = now()
|
||||
WHERE user_id = $1 AND track_id = $2 AND deleted_at IS NULL;
|
||||
|
||||
-- name: ListActiveContextualLikesForUser :many
|
||||
-- Returns all the user's active (non-soft-deleted) contextual_likes with
|
||||
-- non-null vectors. Cardinality is bounded by the user's actual like-while-
|
||||
-- playing history — typically tens to low hundreds. Used by the engine to
|
||||
-- compute contextual_match_score for the candidate pool.
|
||||
SELECT track_id, session_vector
|
||||
FROM contextual_likes
|
||||
WHERE user_id = $1
|
||||
AND deleted_at IS NULL
|
||||
AND session_vector IS NOT NULL;
|
||||
|
||||
@@ -66,3 +66,15 @@ LIMIT $3;
|
||||
UPDATE play_events
|
||||
SET session_vector_at_play = $2
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: GetCurrentSessionVectorForUser :one
|
||||
-- Returns the session_vector_at_play of the user's most recent play_event
|
||||
-- in a still-active (un-timed-out) session. NoRows means no current vector.
|
||||
-- Joined with play_sessions so closed sessions don't leak stale vectors.
|
||||
SELECT pe.session_vector_at_play
|
||||
FROM play_events pe
|
||||
JOIN play_sessions s ON s.id = pe.session_id
|
||||
WHERE pe.user_id = $1
|
||||
AND s.ended_at IS NULL
|
||||
ORDER BY pe.started_at DESC
|
||||
LIMIT 1;
|
||||
|
||||
Reference in New Issue
Block a user