Big changes
This commit is contained in:
@@ -2,12 +2,51 @@ package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
// BrowsingCandidates returns library items the user actively focused or selected,
|
||||
// strongest first. Impressions are intentionally excluded: merely scrolling past a row
|
||||
// is not evidence of taste.
|
||||
func (s *Store) BrowsingCandidates(
|
||||
ctx context.Context,
|
||||
userID string,
|
||||
since time.Time,
|
||||
limit int,
|
||||
) ([]json.RawMessage, error) {
|
||||
rows, err := s.pool.Query(ctx, `
|
||||
SELECT li.payload
|
||||
FROM row_events re
|
||||
JOIN library_items li ON li.id = re.item_id
|
||||
WHERE re.emby_user_id = $1
|
||||
AND re.occurred_at >= $2
|
||||
AND re.event IN ('focus', 'select')
|
||||
GROUP BY li.id, li.payload
|
||||
ORDER BY
|
||||
count(*) FILTER (WHERE re.event = 'select') * 20 +
|
||||
count(*) FILTER (WHERE re.event = 'focus') * 2 +
|
||||
coalesce(sum(re.dwell_ms), 0) / 10000 DESC,
|
||||
max(re.occurred_at) DESC
|
||||
LIMIT $3`, userID, since, limit)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("store: browsing candidates: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
out := []json.RawMessage{}
|
||||
for rows.Next() {
|
||||
var payload []byte
|
||||
if err := rows.Scan(&payload); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, json.RawMessage(payload))
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// RowEvent is one reported interaction with a home-screen row.
|
||||
type RowEvent struct {
|
||||
OccurredAt time.Time
|
||||
|
||||
Reference in New Issue
Block a user