Documentation
¶
Overview ¶
Package ratings caches licensed, owner-keyed rating data. Values preserve their source scale; Plex's main rating fields alone use the 0–10 scale.
Index ¶
- Constants
- type Badge
- type Options
- type Service
- func (s *Service) Cached(ctx context.Context, t *core.Title) ([]Badge, error)
- func (s *Service) MigrateSecrets(ctx context.Context) (int, error)
- func (s *Service) Prune(ctx context.Context) (int64, error)
- func (s *Service) Queue(t core.Title)
- func (s *Service) Refresh(ctx context.Context, t *core.Title) ([]Badge, error)
- func (s *Service) Router(cat core.Catalog) http.Handler
- func (s *Service) Run(ctx context.Context)
- func (s *Service) SaveSettings(ctx context.Context, v Settings) error
- func (s *Service) Settings(ctx context.Context) (Settings, error)
- func (s *Service) WithSettingsSnapshot(ctx context.Context) context.Context
- type Settings
Constants ¶
const Redacted = "[configured]"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Badge ¶
type Badge struct {
Source string `json:"source"`
Value float64 `json:"value"`
Scale float64 `json:"scale"`
Votes int64 `json:"votes,omitempty"`
}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) MigrateSecrets ¶ added in v0.2.4
MigrateSecrets seals an API key stored in plaintext; it returns 1 when it rewrote the settings. The row is replaced only if unchanged since read, and a key that does not open is left untouched.
func (*Service) Prune ¶
Prune deletes rating rows older than the maximum cache interval. It is meant to be called periodically.
func (*Service) Queue ¶
Queue is bounded, deduplicated and nonblocking; Run owns the network worker.
func (*Service) Refresh ¶
Refresh returns fresh-or-cached badges for t.
Semântica de concorrência: nenhum lock é segurado durante o HTTP — flightMu só protege o map flights (leitura/escrita curta), e cache/DB são acessados sem lock global. Chamadas concorrentes para a MESMA key compartilham um único fetch em voo (singleflight): quem espera recebe o resultado (badges/err) do líder, sem disparar outro request. Se o contexto do líder encerrou o fetch (abandoned) e o contexto de quem espera ainda está vivo, quem espera NÃO herda esse erro de cancelamento: ele refaz — vira o próximo líder ou entra no fetch seguinte. Se o contexto de quem espera é cancelado enquanto aguarda, ele retorna ctx.Err() sem cancelar o fetch do líder. Keys diferentes fazem fetch em paralelo.