0.3.07
This commit is contained in:
@@ -68,6 +68,46 @@ type SonarrSeriesStatusChange struct {
|
||||
Current SonarrSeriesStatus
|
||||
}
|
||||
|
||||
// LatestSonarrSeriesStatuses returns Sonarr's most recently observed lifecycle for each
|
||||
// TVDB id. The history table is change-only, so the newest row is also the current value.
|
||||
func (s *Store) LatestSonarrSeriesStatuses(
|
||||
ctx context.Context, tvdbIDs []int,
|
||||
) (map[int]string, error) {
|
||||
statuses := map[int]string{}
|
||||
if len(tvdbIDs) == 0 {
|
||||
return statuses, nil
|
||||
}
|
||||
rows, err := s.pool.Query(ctx, `
|
||||
SELECT DISTINCT ON (tvdb_id) tvdb_id, status
|
||||
FROM sonarr_series_status_history
|
||||
WHERE tvdb_id = ANY($1) AND tvdb_id > 0
|
||||
ORDER BY tvdb_id, observed_at DESC, id DESC`, tvdbIDs)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("store: read latest Sonarr series statuses: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var tvdbID int
|
||||
var status string
|
||||
if err := rows.Scan(&tvdbID, &status); err != nil {
|
||||
return nil, fmt.Errorf("store: scan latest Sonarr series status: %w", err)
|
||||
}
|
||||
statuses[tvdbID] = status
|
||||
}
|
||||
return statuses, rows.Err()
|
||||
}
|
||||
|
||||
// SonarrSeriesStatusRevision is an opaque, monotonic version of the stored lifecycle
|
||||
// catalogue. It changes whenever a scan records a first sighting or a transition.
|
||||
func (s *Store) SonarrSeriesStatusRevision(ctx context.Context) (int64, error) {
|
||||
var revision int64
|
||||
if err := s.pool.QueryRow(ctx,
|
||||
`SELECT COALESCE(max(id), 0) FROM sonarr_series_status_history`).Scan(&revision); err != nil {
|
||||
return 0, fmt.Errorf("store: read Sonarr series status revision: %w", err)
|
||||
}
|
||||
return revision, nil
|
||||
}
|
||||
|
||||
func (s *Store) SaveUserShow(ctx context.Context, userID string, show UserShow) error {
|
||||
_, err := s.pool.Exec(ctx, `
|
||||
INSERT INTO user_shows (emby_user_id, item_id, title, year, image_tag)
|
||||
|
||||
Reference in New Issue
Block a user