0.2.78
This commit is contained in:
@@ -223,6 +223,40 @@ func (s *Store) MediaRatingsStats(ctx context.Context, staleBefore time.Time) (t
|
||||
return total, stale, nil
|
||||
}
|
||||
|
||||
// StaleRatingKeys is the oldest stored titles due to be re-checked, oldest first.
|
||||
//
|
||||
// Oldest first rather than by any measure of popularity, because the refresh is bounded
|
||||
// per run: taking the oldest means every title comes round eventually, where taking the
|
||||
// most-watched would leave the tail of the library permanently on scores from the year it
|
||||
// was imported. The limit is what keeps a run's cost — and therefore the day's external
|
||||
// allowance — a figure the operator can reason about.
|
||||
func (s *Store) StaleRatingKeys(
|
||||
ctx context.Context, staleBefore time.Time, limit int,
|
||||
) ([]RatingKey, error) {
|
||||
if limit <= 0 || limit > 500 {
|
||||
limit = 100
|
||||
}
|
||||
rows, err := s.pool.Query(ctx, `
|
||||
SELECT media_type, provider, provider_id
|
||||
FROM external_media_ratings
|
||||
WHERE fetched_at < $1
|
||||
ORDER BY fetched_at ASC
|
||||
LIMIT $2`, staleBefore, limit)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("store: stale rating keys: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
keys := []RatingKey{}
|
||||
for rows.Next() {
|
||||
var key RatingKey
|
||||
if err := rows.Scan(&key.MediaType, &key.Provider, &key.ProviderID); err != nil {
|
||||
return nil, fmt.Errorf("store: scan stale rating key: %w", err)
|
||||
}
|
||||
keys = append(keys, key)
|
||||
}
|
||||
return keys, rows.Err()
|
||||
}
|
||||
|
||||
// SaveMediaRatings upserts a successfully loaded provider response.
|
||||
func (s *Store) SaveMediaRatings(
|
||||
ctx context.Context, mediaType, provider, providerID string, ratings json.RawMessage,
|
||||
|
||||
Reference in New Issue
Block a user