feat: import with verification, and a Wanted view of its own (M502 #5522)
release / govulncheck (push) Successful in 14s
release / web (push) Failing after 15s
release / go (push) Failing after 1m16s
release / integration (push) Failing after 4m49s
release / android (push) Successful in 4m59s
release / Build signed APK (releases and dev) (push) Successful in 5m14s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Skipped
release / Verify release artifacts (tag releases only) (push) Skipped
release / govulncheck (push) Successful in 14s
release / web (push) Failing after 15s
release / go (push) Failing after 1m16s
release / integration (push) Failing after 4m49s
release / android (push) Successful in 4m59s
release / Build signed APK (releases and dev) (push) Successful in 5m14s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Skipped
release / Verify release artifacts (tag releases only) (push) Skipped
A finished download is checked against MusicBrainz before anything is filed: the files are paired with an edition's tracks by position or path, and AcoustID, tag ids, lengths and titles say whether it is the album. What is the album is copied into the library as Artist/Album (Year)/Artist - Album - NN - Title, tagged with Picard's MusicBrainz ids, and scanned; the download keeps seeding. What is not is refused: set aside, removed from the client, and the album searched for again. A download the check cannot settle waits for a person, who imports it anyway or refuses it. Tracks the library already holds are skipped. The wanted list leaves Admin for a top-level Wanted view, admin-only and web-only, with tabs for Wanted, Activity (downloads and their imports, the ones needing a person first), Missing files, Held, Following (with the release-type profiles, moved off Integrations) and Blocked. The search settings gain "File new music into" when the library has several folders. The search pass logs why each failed search failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,719 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: imports.sql
|
||||
|
||||
package dbq
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const claimGrabImport = `-- name: ClaimGrabImport :one
|
||||
UPDATE grabs
|
||||
SET import_state = 'importing', import_attempts = import_attempts + 1,
|
||||
import_updated_at = now(), progress = 1
|
||||
WHERE id = $1 AND ended_at IS NULL AND import_state IN ('', 'downloading', 'waiting')
|
||||
RETURNING id, want_id, info_hash, name, key, indexer, source, client, save_path, quality, origin, forced, grabbed_by, grabbed_at, ended_at, end_reason, end_detail, progress, import_state, import_reason, import_detail, import_forced, import_attempts, import_updated_at, imported_at, imported_files, destination
|
||||
`
|
||||
|
||||
// Takes a finished download for import. The update is the lock: a second
|
||||
// pass finds nothing to claim.
|
||||
func (q *Queries) ClaimGrabImport(ctx context.Context, id pgtype.UUID) (Grab, error) {
|
||||
row := q.db.QueryRow(ctx, claimGrabImport, id)
|
||||
var i Grab
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.WantID,
|
||||
&i.InfoHash,
|
||||
&i.Name,
|
||||
&i.Key,
|
||||
&i.Indexer,
|
||||
&i.Source,
|
||||
&i.Client,
|
||||
&i.SavePath,
|
||||
&i.Quality,
|
||||
&i.Origin,
|
||||
&i.Forced,
|
||||
&i.GrabbedBy,
|
||||
&i.GrabbedAt,
|
||||
&i.EndedAt,
|
||||
&i.EndReason,
|
||||
&i.EndDetail,
|
||||
&i.Progress,
|
||||
&i.ImportState,
|
||||
&i.ImportReason,
|
||||
&i.ImportDetail,
|
||||
&i.ImportForced,
|
||||
&i.ImportAttempts,
|
||||
&i.ImportUpdatedAt,
|
||||
&i.ImportedAt,
|
||||
&i.ImportedFiles,
|
||||
&i.Destination,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const forceGrabImport = `-- name: ForceGrabImport :one
|
||||
UPDATE grabs
|
||||
SET import_state = '', import_forced = true, import_reason = '', import_updated_at = now()
|
||||
WHERE id = $1 AND ended_at IS NULL AND import_state IN ('review', 'failed')
|
||||
RETURNING id, want_id, info_hash, name, key, indexer, source, client, save_path, quality, origin, forced, grabbed_by, grabbed_at, ended_at, end_reason, end_detail, progress, import_state, import_reason, import_detail, import_forced, import_attempts, import_updated_at, imported_at, imported_files, destination
|
||||
`
|
||||
|
||||
// "Import anyway": the next pass imports the download whatever the check said.
|
||||
func (q *Queries) ForceGrabImport(ctx context.Context, id pgtype.UUID) (Grab, error) {
|
||||
row := q.db.QueryRow(ctx, forceGrabImport, id)
|
||||
var i Grab
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.WantID,
|
||||
&i.InfoHash,
|
||||
&i.Name,
|
||||
&i.Key,
|
||||
&i.Indexer,
|
||||
&i.Source,
|
||||
&i.Client,
|
||||
&i.SavePath,
|
||||
&i.Quality,
|
||||
&i.Origin,
|
||||
&i.Forced,
|
||||
&i.GrabbedBy,
|
||||
&i.GrabbedAt,
|
||||
&i.EndedAt,
|
||||
&i.EndReason,
|
||||
&i.EndDetail,
|
||||
&i.Progress,
|
||||
&i.ImportState,
|
||||
&i.ImportReason,
|
||||
&i.ImportDetail,
|
||||
&i.ImportForced,
|
||||
&i.ImportAttempts,
|
||||
&i.ImportUpdatedAt,
|
||||
&i.ImportedAt,
|
||||
&i.ImportedFiles,
|
||||
&i.Destination,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getGrab = `-- name: GetGrab :one
|
||||
SELECT id, want_id, info_hash, name, key, indexer, source, client, save_path, quality, origin, forced, grabbed_by, grabbed_at, ended_at, end_reason, end_detail, progress, import_state, import_reason, import_detail, import_forced, import_attempts, import_updated_at, imported_at, imported_files, destination FROM grabs WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetGrab(ctx context.Context, id pgtype.UUID) (Grab, error) {
|
||||
row := q.db.QueryRow(ctx, getGrab, id)
|
||||
var i Grab
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.WantID,
|
||||
&i.InfoHash,
|
||||
&i.Name,
|
||||
&i.Key,
|
||||
&i.Indexer,
|
||||
&i.Source,
|
||||
&i.Client,
|
||||
&i.SavePath,
|
||||
&i.Quality,
|
||||
&i.Origin,
|
||||
&i.Forced,
|
||||
&i.GrabbedBy,
|
||||
&i.GrabbedAt,
|
||||
&i.EndedAt,
|
||||
&i.EndReason,
|
||||
&i.EndDetail,
|
||||
&i.Progress,
|
||||
&i.ImportState,
|
||||
&i.ImportReason,
|
||||
&i.ImportDetail,
|
||||
&i.ImportForced,
|
||||
&i.ImportAttempts,
|
||||
&i.ImportUpdatedAt,
|
||||
&i.ImportedAt,
|
||||
&i.ImportedFiles,
|
||||
&i.Destination,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const heldPositions = `-- name: HeldPositions :many
|
||||
SELECT DISTINCT COALESCE(t.disc_number, 1)::int AS disc, t.track_number::int AS track
|
||||
FROM tracks t
|
||||
JOIN albums a ON a.id = t.album_id
|
||||
WHERE a.release_group_mbid = $1
|
||||
AND t.missing_since IS NULL AND t.track_number IS NOT NULL
|
||||
`
|
||||
|
||||
type HeldPositionsRow struct {
|
||||
Disc int32
|
||||
Track int32
|
||||
}
|
||||
|
||||
// The disc and track positions the library holds for an album of this group.
|
||||
func (q *Queries) HeldPositions(ctx context.Context, releaseGroupMbid *string) ([]HeldPositionsRow, error) {
|
||||
rows, err := q.db.Query(ctx, heldPositions, releaseGroupMbid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []HeldPositionsRow
|
||||
for rows.Next() {
|
||||
var i HeldPositionsRow
|
||||
if err := rows.Scan(&i.Disc, &i.Track); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const heldRecordings = `-- name: HeldRecordings :many
|
||||
SELECT DISTINCT mbid::text AS mbid FROM tracks
|
||||
WHERE mbid = ANY($1::text[]) AND missing_since IS NULL
|
||||
`
|
||||
|
||||
// Which of these recordings the library holds a file for.
|
||||
func (q *Queries) HeldRecordings(ctx context.Context, recordings []string) ([]string, error) {
|
||||
rows, err := q.db.Query(ctx, heldRecordings, recordings)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []string
|
||||
for rows.Next() {
|
||||
var mbid string
|
||||
if err := rows.Scan(&mbid); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, mbid)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listGrabs = `-- name: ListGrabs :many
|
||||
SELECT g.id, g.want_id, g.name, g.indexer, g.client, g.quality, g.origin, g.forced,
|
||||
g.grabbed_at, g.ended_at, g.end_reason, g.end_detail, g.progress, g.import_state,
|
||||
g.import_reason, g.import_detail, g.import_updated_at, g.imported_at, g.imported_files,
|
||||
g.destination, w.title AS want_title, w.artist_name AS want_artist
|
||||
FROM grabs g
|
||||
LEFT JOIN wants w ON w.id = g.want_id
|
||||
ORDER BY (g.ended_at IS NULL AND g.import_state IN ('review', 'failed')) DESC,
|
||||
g.ended_at IS NULL DESC, g.grabbed_at DESC, g.id
|
||||
LIMIT $2 OFFSET $1
|
||||
`
|
||||
|
||||
type ListGrabsParams struct {
|
||||
Skip int32
|
||||
MaxRows int32
|
||||
}
|
||||
|
||||
type ListGrabsRow struct {
|
||||
ID pgtype.UUID
|
||||
WantID pgtype.UUID
|
||||
Name string
|
||||
Indexer string
|
||||
Client string
|
||||
Quality string
|
||||
Origin string
|
||||
Forced bool
|
||||
GrabbedAt pgtype.Timestamptz
|
||||
EndedAt pgtype.Timestamptz
|
||||
EndReason string
|
||||
EndDetail string
|
||||
Progress float32
|
||||
ImportState string
|
||||
ImportReason string
|
||||
ImportDetail []byte
|
||||
ImportUpdatedAt pgtype.Timestamptz
|
||||
ImportedAt pgtype.Timestamptz
|
||||
ImportedFiles int32
|
||||
Destination string
|
||||
WantTitle *string
|
||||
WantArtist *string
|
||||
}
|
||||
|
||||
// The Wanted view's Activity tab: downloads waiting on a person first, then
|
||||
// the rest still running, then the ended ones newest first.
|
||||
func (q *Queries) ListGrabs(ctx context.Context, arg ListGrabsParams) ([]ListGrabsRow, error) {
|
||||
rows, err := q.db.Query(ctx, listGrabs, arg.Skip, arg.MaxRows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListGrabsRow
|
||||
for rows.Next() {
|
||||
var i ListGrabsRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.WantID,
|
||||
&i.Name,
|
||||
&i.Indexer,
|
||||
&i.Client,
|
||||
&i.Quality,
|
||||
&i.Origin,
|
||||
&i.Forced,
|
||||
&i.GrabbedAt,
|
||||
&i.EndedAt,
|
||||
&i.EndReason,
|
||||
&i.EndDetail,
|
||||
&i.Progress,
|
||||
&i.ImportState,
|
||||
&i.ImportReason,
|
||||
&i.ImportDetail,
|
||||
&i.ImportUpdatedAt,
|
||||
&i.ImportedAt,
|
||||
&i.ImportedFiles,
|
||||
&i.Destination,
|
||||
&i.WantTitle,
|
||||
&i.WantArtist,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listLiveGrabs = `-- name: ListLiveGrabs :many
|
||||
|
||||
SELECT g.id, g.want_id, g.info_hash, g.name, g.key, g.indexer, g.source, g.client, g.save_path, g.quality, g.origin, g.forced, g.grabbed_by, g.grabbed_at, g.ended_at, g.end_reason, g.end_detail, g.progress, g.import_state, g.import_reason, g.import_detail, g.import_forced, g.import_attempts, g.import_updated_at, g.imported_at, g.imported_files, g.destination, w.release_group_mbid, w.artist_mbid, w.artist_name, w.title AS want_title,
|
||||
w.reason AS want_reason, w.album_id AS want_album_id
|
||||
FROM grabs g
|
||||
LEFT JOIN wants w ON w.id = g.want_id
|
||||
WHERE g.ended_at IS NULL
|
||||
ORDER BY g.grabbed_at, g.id
|
||||
`
|
||||
|
||||
type ListLiveGrabsRow struct {
|
||||
ID pgtype.UUID
|
||||
WantID pgtype.UUID
|
||||
InfoHash string
|
||||
Name string
|
||||
Key string
|
||||
Indexer string
|
||||
Source string
|
||||
Client string
|
||||
SavePath string
|
||||
Quality string
|
||||
Origin string
|
||||
Forced bool
|
||||
GrabbedBy pgtype.UUID
|
||||
GrabbedAt pgtype.Timestamptz
|
||||
EndedAt pgtype.Timestamptz
|
||||
EndReason string
|
||||
EndDetail string
|
||||
Progress float32
|
||||
ImportState string
|
||||
ImportReason string
|
||||
ImportDetail []byte
|
||||
ImportForced bool
|
||||
ImportAttempts int32
|
||||
ImportUpdatedAt pgtype.Timestamptz
|
||||
ImportedAt pgtype.Timestamptz
|
||||
ImportedFiles int32
|
||||
Destination string
|
||||
ReleaseGroupMbid *string
|
||||
ArtistMbid *string
|
||||
ArtistName *string
|
||||
WantTitle *string
|
||||
WantReason *string
|
||||
WantAlbumID pgtype.UUID
|
||||
}
|
||||
|
||||
// Import with verification (M502 #5522).
|
||||
// Every download still running or waiting on its import, oldest first.
|
||||
func (q *Queries) ListLiveGrabs(ctx context.Context) ([]ListLiveGrabsRow, error) {
|
||||
rows, err := q.db.Query(ctx, listLiveGrabs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListLiveGrabsRow
|
||||
for rows.Next() {
|
||||
var i ListLiveGrabsRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.WantID,
|
||||
&i.InfoHash,
|
||||
&i.Name,
|
||||
&i.Key,
|
||||
&i.Indexer,
|
||||
&i.Source,
|
||||
&i.Client,
|
||||
&i.SavePath,
|
||||
&i.Quality,
|
||||
&i.Origin,
|
||||
&i.Forced,
|
||||
&i.GrabbedBy,
|
||||
&i.GrabbedAt,
|
||||
&i.EndedAt,
|
||||
&i.EndReason,
|
||||
&i.EndDetail,
|
||||
&i.Progress,
|
||||
&i.ImportState,
|
||||
&i.ImportReason,
|
||||
&i.ImportDetail,
|
||||
&i.ImportForced,
|
||||
&i.ImportAttempts,
|
||||
&i.ImportUpdatedAt,
|
||||
&i.ImportedAt,
|
||||
&i.ImportedFiles,
|
||||
&i.Destination,
|
||||
&i.ReleaseGroupMbid,
|
||||
&i.ArtistMbid,
|
||||
&i.ArtistName,
|
||||
&i.WantTitle,
|
||||
&i.WantReason,
|
||||
&i.WantAlbumID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listReleaseBlocksPage = `-- name: ListReleaseBlocksPage :many
|
||||
SELECT b.info_hash, b.name, b.reason, b.detail, b.blocked_at, w.title AS want_title,
|
||||
w.artist_name AS want_artist
|
||||
FROM release_blocks b
|
||||
LEFT JOIN wants w ON w.id = b.want_id
|
||||
ORDER BY b.blocked_at DESC, b.info_hash
|
||||
LIMIT $2 OFFSET $1
|
||||
`
|
||||
|
||||
type ListReleaseBlocksPageParams struct {
|
||||
Skip int32
|
||||
MaxRows int32
|
||||
}
|
||||
|
||||
type ListReleaseBlocksPageRow struct {
|
||||
InfoHash string
|
||||
Name string
|
||||
Reason string
|
||||
Detail string
|
||||
BlockedAt pgtype.Timestamptz
|
||||
WantTitle *string
|
||||
WantArtist *string
|
||||
}
|
||||
|
||||
func (q *Queries) ListReleaseBlocksPage(ctx context.Context, arg ListReleaseBlocksPageParams) ([]ListReleaseBlocksPageRow, error) {
|
||||
rows, err := q.db.Query(ctx, listReleaseBlocksPage, arg.Skip, arg.MaxRows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListReleaseBlocksPageRow
|
||||
for rows.Next() {
|
||||
var i ListReleaseBlocksPageRow
|
||||
if err := rows.Scan(
|
||||
&i.InfoHash,
|
||||
&i.Name,
|
||||
&i.Reason,
|
||||
&i.Detail,
|
||||
&i.BlockedAt,
|
||||
&i.WantTitle,
|
||||
&i.WantArtist,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const markWantSearched = `-- name: MarkWantSearched :exec
|
||||
UPDATE wants SET searched_at = now() WHERE id = $1
|
||||
`
|
||||
|
||||
// Imported: nothing to search for until the wanted pass settles the want.
|
||||
func (q *Queries) MarkWantSearched(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, markWantSearched, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const openWantsForGroups = `-- name: OpenWantsForGroups :many
|
||||
SELECT w.id, w.release_group_mbid, w.artist_mbid, w.artist_name, w.title, w.primary_type, w.first_release_date, w.reason, w.album_id, w.created_by, w.wanted_at, w.fulfilled_at, w.created_at, w.updated_at, w.searched_at, w.search_outcome, w.search_considered, w.best_release, w.best_verdict, w.search_error FROM wants w
|
||||
WHERE w.fulfilled_at IS NULL AND w.release_group_mbid = ANY($1::text[])
|
||||
AND NOT EXISTS (SELECT 1 FROM grabs g WHERE g.want_id = w.id AND g.ended_at IS NULL)
|
||||
`
|
||||
|
||||
// Open wants for these release groups with no download running.
|
||||
func (q *Queries) OpenWantsForGroups(ctx context.Context, groups []string) ([]Want, error) {
|
||||
rows, err := q.db.Query(ctx, openWantsForGroups, groups)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Want
|
||||
for rows.Next() {
|
||||
var i Want
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ReleaseGroupMbid,
|
||||
&i.ArtistMbid,
|
||||
&i.ArtistName,
|
||||
&i.Title,
|
||||
&i.PrimaryType,
|
||||
&i.FirstReleaseDate,
|
||||
&i.Reason,
|
||||
&i.AlbumID,
|
||||
&i.CreatedBy,
|
||||
&i.WantedAt,
|
||||
&i.FulfilledAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.SearchedAt,
|
||||
&i.SearchOutcome,
|
||||
&i.SearchConsidered,
|
||||
&i.BestRelease,
|
||||
&i.BestVerdict,
|
||||
&i.SearchError,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const reclaimStaleImports = `-- name: ReclaimStaleImports :execrows
|
||||
UPDATE grabs
|
||||
SET import_state = 'waiting',
|
||||
import_reason = 'The last import was cut short, so it is being tried again.'
|
||||
WHERE ended_at IS NULL AND import_state = 'importing'
|
||||
AND import_updated_at < now() - make_interval(mins => $1::int)
|
||||
`
|
||||
|
||||
// An import cut short (a restart mid-copy) is tried again.
|
||||
func (q *Queries) ReclaimStaleImports(ctx context.Context, minutes int32) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, reclaimStaleImports, minutes)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const recordImport = `-- name: RecordImport :one
|
||||
UPDATE grabs
|
||||
SET import_state = $1,
|
||||
import_reason = $2,
|
||||
import_detail = $3,
|
||||
import_updated_at = now(),
|
||||
import_forced = false,
|
||||
imported_at = CASE WHEN $1::text = 'imported' THEN now() ELSE imported_at END,
|
||||
imported_files = $4,
|
||||
destination = $5,
|
||||
ended_at = CASE WHEN $6::text <> '' THEN now() ELSE ended_at END,
|
||||
end_reason = $6,
|
||||
end_detail = CASE WHEN $6::text <> '' THEN $2::text ELSE end_detail END
|
||||
WHERE id = $7
|
||||
RETURNING id, want_id, info_hash, name, key, indexer, source, client, save_path, quality, origin, forced, grabbed_by, grabbed_at, ended_at, end_reason, end_detail, progress, import_state, import_reason, import_detail, import_forced, import_attempts, import_updated_at, imported_at, imported_files, destination
|
||||
`
|
||||
|
||||
type RecordImportParams struct {
|
||||
ImportState string
|
||||
ImportReason string
|
||||
ImportDetail []byte
|
||||
ImportedFiles int32
|
||||
Destination string
|
||||
EndReason string
|
||||
ID pgtype.UUID
|
||||
}
|
||||
|
||||
// The import's outcome. An end reason ends the grab: imported, refused or
|
||||
// held. Without one the grab stays live: review and failed wait for a person.
|
||||
func (q *Queries) RecordImport(ctx context.Context, arg RecordImportParams) (Grab, error) {
|
||||
row := q.db.QueryRow(ctx, recordImport,
|
||||
arg.ImportState,
|
||||
arg.ImportReason,
|
||||
arg.ImportDetail,
|
||||
arg.ImportedFiles,
|
||||
arg.Destination,
|
||||
arg.EndReason,
|
||||
arg.ID,
|
||||
)
|
||||
var i Grab
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.WantID,
|
||||
&i.InfoHash,
|
||||
&i.Name,
|
||||
&i.Key,
|
||||
&i.Indexer,
|
||||
&i.Source,
|
||||
&i.Client,
|
||||
&i.SavePath,
|
||||
&i.Quality,
|
||||
&i.Origin,
|
||||
&i.Forced,
|
||||
&i.GrabbedBy,
|
||||
&i.GrabbedAt,
|
||||
&i.EndedAt,
|
||||
&i.EndReason,
|
||||
&i.EndDetail,
|
||||
&i.Progress,
|
||||
&i.ImportState,
|
||||
&i.ImportReason,
|
||||
&i.ImportDetail,
|
||||
&i.ImportForced,
|
||||
&i.ImportAttempts,
|
||||
&i.ImportUpdatedAt,
|
||||
&i.ImportedAt,
|
||||
&i.ImportedFiles,
|
||||
&i.Destination,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const rehomeGrab = `-- name: RehomeGrab :one
|
||||
UPDATE grabs g
|
||||
SET want_id = $1
|
||||
WHERE g.id = $2 AND g.ended_at IS NULL
|
||||
AND NOT EXISTS (SELECT 1 FROM grabs o WHERE o.want_id = $1 AND o.ended_at IS NULL)
|
||||
RETURNING id, want_id, info_hash, name, key, indexer, source, client, save_path, quality, origin, forced, grabbed_by, grabbed_at, ended_at, end_reason, end_detail, progress, import_state, import_reason, import_detail, import_forced, import_attempts, import_updated_at, imported_at, imported_files, destination
|
||||
`
|
||||
|
||||
type RehomeGrabParams struct {
|
||||
WantID pgtype.UUID
|
||||
ID pgtype.UUID
|
||||
}
|
||||
|
||||
// A download that turned out to be another wanted album is that want's grab,
|
||||
// when the want has none running.
|
||||
func (q *Queries) RehomeGrab(ctx context.Context, arg RehomeGrabParams) (Grab, error) {
|
||||
row := q.db.QueryRow(ctx, rehomeGrab, arg.WantID, arg.ID)
|
||||
var i Grab
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.WantID,
|
||||
&i.InfoHash,
|
||||
&i.Name,
|
||||
&i.Key,
|
||||
&i.Indexer,
|
||||
&i.Source,
|
||||
&i.Client,
|
||||
&i.SavePath,
|
||||
&i.Quality,
|
||||
&i.Origin,
|
||||
&i.Forced,
|
||||
&i.GrabbedBy,
|
||||
&i.GrabbedAt,
|
||||
&i.EndedAt,
|
||||
&i.EndReason,
|
||||
&i.EndDetail,
|
||||
&i.Progress,
|
||||
&i.ImportState,
|
||||
&i.ImportReason,
|
||||
&i.ImportDetail,
|
||||
&i.ImportForced,
|
||||
&i.ImportAttempts,
|
||||
&i.ImportUpdatedAt,
|
||||
&i.ImportedAt,
|
||||
&i.ImportedFiles,
|
||||
&i.Destination,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const retryGrabImport = `-- name: RetryGrabImport :one
|
||||
UPDATE grabs
|
||||
SET import_state = '', import_reason = '', import_updated_at = now()
|
||||
WHERE id = $1 AND ended_at IS NULL AND import_state = 'failed'
|
||||
RETURNING id, want_id, info_hash, name, key, indexer, source, client, save_path, quality, origin, forced, grabbed_by, grabbed_at, ended_at, end_reason, end_detail, progress, import_state, import_reason, import_detail, import_forced, import_attempts, import_updated_at, imported_at, imported_files, destination
|
||||
`
|
||||
|
||||
func (q *Queries) RetryGrabImport(ctx context.Context, id pgtype.UUID) (Grab, error) {
|
||||
row := q.db.QueryRow(ctx, retryGrabImport, id)
|
||||
var i Grab
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.WantID,
|
||||
&i.InfoHash,
|
||||
&i.Name,
|
||||
&i.Key,
|
||||
&i.Indexer,
|
||||
&i.Source,
|
||||
&i.Client,
|
||||
&i.SavePath,
|
||||
&i.Quality,
|
||||
&i.Origin,
|
||||
&i.Forced,
|
||||
&i.GrabbedBy,
|
||||
&i.GrabbedAt,
|
||||
&i.EndedAt,
|
||||
&i.EndReason,
|
||||
&i.EndDetail,
|
||||
&i.Progress,
|
||||
&i.ImportState,
|
||||
&i.ImportReason,
|
||||
&i.ImportDetail,
|
||||
&i.ImportForced,
|
||||
&i.ImportAttempts,
|
||||
&i.ImportUpdatedAt,
|
||||
&i.ImportedAt,
|
||||
&i.ImportedFiles,
|
||||
&i.Destination,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const searchWantAgain = `-- name: SearchWantAgain :exec
|
||||
UPDATE wants SET searched_at = NULL, search_outcome = '' WHERE id = $1
|
||||
`
|
||||
|
||||
// Refused: search again on the next pass.
|
||||
func (q *Queries) SearchWantAgain(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, searchWantAgain, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const setGrabProgress = `-- name: SetGrabProgress :exec
|
||||
UPDATE grabs
|
||||
SET progress = $1,
|
||||
import_state = $2,
|
||||
import_reason = $3,
|
||||
import_updated_at = now()
|
||||
WHERE id = $4 AND ended_at IS NULL
|
||||
AND import_state IN ('', 'downloading', 'waiting')
|
||||
`
|
||||
|
||||
type SetGrabProgressParams struct {
|
||||
Progress float32
|
||||
ImportState string
|
||||
ImportReason string
|
||||
ID pgtype.UUID
|
||||
}
|
||||
|
||||
// What the download client says of a download not yet finished, or finished
|
||||
// and waiting for what the import needs. Leaves a claimed, decided or failed
|
||||
// import alone.
|
||||
func (q *Queries) SetGrabProgress(ctx context.Context, arg SetGrabProgressParams) error {
|
||||
_, err := q.db.Exec(ctx, setGrabProgress,
|
||||
arg.Progress,
|
||||
arg.ImportState,
|
||||
arg.ImportReason,
|
||||
arg.ID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
+28
-17
@@ -225,6 +225,7 @@ type AcquisitionSetting struct {
|
||||
LastPassAt pgtype.Timestamptz
|
||||
LastPass []byte
|
||||
UpdatedAt pgtype.Timestamptz
|
||||
ImportRoot string
|
||||
}
|
||||
|
||||
type Album struct {
|
||||
@@ -431,23 +432,33 @@ type GeneralLikesArtist struct {
|
||||
}
|
||||
|
||||
type Grab struct {
|
||||
ID pgtype.UUID
|
||||
WantID pgtype.UUID
|
||||
InfoHash string
|
||||
Name string
|
||||
Key string
|
||||
Indexer string
|
||||
Source string
|
||||
Client string
|
||||
SavePath string
|
||||
Quality string
|
||||
Origin string
|
||||
Forced bool
|
||||
GrabbedBy pgtype.UUID
|
||||
GrabbedAt pgtype.Timestamptz
|
||||
EndedAt pgtype.Timestamptz
|
||||
EndReason string
|
||||
EndDetail string
|
||||
ID pgtype.UUID
|
||||
WantID pgtype.UUID
|
||||
InfoHash string
|
||||
Name string
|
||||
Key string
|
||||
Indexer string
|
||||
Source string
|
||||
Client string
|
||||
SavePath string
|
||||
Quality string
|
||||
Origin string
|
||||
Forced bool
|
||||
GrabbedBy pgtype.UUID
|
||||
GrabbedAt pgtype.Timestamptz
|
||||
EndedAt pgtype.Timestamptz
|
||||
EndReason string
|
||||
EndDetail string
|
||||
Progress float32
|
||||
ImportState string
|
||||
ImportReason string
|
||||
ImportDetail []byte
|
||||
ImportForced bool
|
||||
ImportAttempts int32
|
||||
ImportUpdatedAt pgtype.Timestamptz
|
||||
ImportedAt pgtype.Timestamptz
|
||||
ImportedFiles int32
|
||||
Destination string
|
||||
}
|
||||
|
||||
type LibraryChange struct {
|
||||
|
||||
@@ -89,7 +89,7 @@ func (q *Queries) EndGrab(ctx context.Context, arg EndGrabParams) error {
|
||||
|
||||
const getAcquisitionSettings = `-- name: GetAcquisitionSettings :one
|
||||
|
||||
SELECT id, auto_grab, search_interval_hours, allowed_qualities, last_pass_at, last_pass, updated_at FROM acquisition_settings WHERE id = true
|
||||
SELECT id, auto_grab, search_interval_hours, allowed_qualities, last_pass_at, last_pass, updated_at, import_root FROM acquisition_settings WHERE id = true
|
||||
`
|
||||
|
||||
// Searching for wants and grabbing releases (M502 #5521).
|
||||
@@ -104,12 +104,13 @@ func (q *Queries) GetAcquisitionSettings(ctx context.Context) (AcquisitionSettin
|
||||
&i.LastPassAt,
|
||||
&i.LastPass,
|
||||
&i.UpdatedAt,
|
||||
&i.ImportRoot,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getLiveGrab = `-- name: GetLiveGrab :one
|
||||
SELECT id, want_id, info_hash, name, key, indexer, source, client, save_path, quality, origin, forced, grabbed_by, grabbed_at, ended_at, end_reason, end_detail FROM grabs WHERE want_id = $1 AND ended_at IS NULL
|
||||
SELECT id, want_id, info_hash, name, key, indexer, source, client, save_path, quality, origin, forced, grabbed_by, grabbed_at, ended_at, end_reason, end_detail, progress, import_state, import_reason, import_detail, import_forced, import_attempts, import_updated_at, imported_at, imported_files, destination FROM grabs WHERE want_id = $1 AND ended_at IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) GetLiveGrab(ctx context.Context, wantID pgtype.UUID) (Grab, error) {
|
||||
@@ -133,6 +134,16 @@ func (q *Queries) GetLiveGrab(ctx context.Context, wantID pgtype.UUID) (Grab, er
|
||||
&i.EndedAt,
|
||||
&i.EndReason,
|
||||
&i.EndDetail,
|
||||
&i.Progress,
|
||||
&i.ImportState,
|
||||
&i.ImportReason,
|
||||
&i.ImportDetail,
|
||||
&i.ImportForced,
|
||||
&i.ImportAttempts,
|
||||
&i.ImportUpdatedAt,
|
||||
&i.ImportedAt,
|
||||
&i.ImportedFiles,
|
||||
&i.Destination,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -173,7 +184,7 @@ func (q *Queries) GetWantCandidate(ctx context.Context, arg GetWantCandidatePara
|
||||
}
|
||||
|
||||
const getWantForSearch = `-- name: GetWantForSearch :one
|
||||
SELECT w.id, w.release_group_mbid, w.artist_name, w.title, w.reason, w.fulfilled_at,
|
||||
SELECT w.id, w.release_group_mbid, w.artist_mbid, w.artist_name, w.title, w.reason, w.fulfilled_at,
|
||||
COALESCE(NULLIF(w.primary_type, ''), g.primary_type, '')::text AS primary_type,
|
||||
COALESCE(g.secondary_types, '{}')::text[] AS secondary_types,
|
||||
COALESCE(NULLIF(w.first_release_date, ''), g.first_release_date, '')::text AS first_release_date
|
||||
@@ -185,6 +196,7 @@ SELECT w.id, w.release_group_mbid, w.artist_name, w.title, w.reason, w.fulfilled
|
||||
type GetWantForSearchRow struct {
|
||||
ID pgtype.UUID
|
||||
ReleaseGroupMbid string
|
||||
ArtistMbid string
|
||||
ArtistName string
|
||||
Title string
|
||||
Reason string
|
||||
@@ -200,6 +212,7 @@ func (q *Queries) GetWantForSearch(ctx context.Context, id pgtype.UUID) (GetWant
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ReleaseGroupMbid,
|
||||
&i.ArtistMbid,
|
||||
&i.ArtistName,
|
||||
&i.Title,
|
||||
&i.Reason,
|
||||
@@ -217,7 +230,7 @@ INSERT INTO grabs (want_id, info_hash, name, key, indexer, source, client, save_
|
||||
VALUES ($1, $2, $3, $4, $5,
|
||||
$6, $7, $8, $9,
|
||||
$10, $11, $12)
|
||||
RETURNING id, want_id, info_hash, name, key, indexer, source, client, save_path, quality, origin, forced, grabbed_by, grabbed_at, ended_at, end_reason, end_detail
|
||||
RETURNING id, want_id, info_hash, name, key, indexer, source, client, save_path, quality, origin, forced, grabbed_by, grabbed_at, ended_at, end_reason, end_detail, progress, import_state, import_reason, import_detail, import_forced, import_attempts, import_updated_at, imported_at, imported_files, destination
|
||||
`
|
||||
|
||||
type InsertGrabParams struct {
|
||||
@@ -269,6 +282,16 @@ func (q *Queries) InsertGrab(ctx context.Context, arg InsertGrabParams) (Grab, e
|
||||
&i.EndedAt,
|
||||
&i.EndReason,
|
||||
&i.EndDetail,
|
||||
&i.Progress,
|
||||
&i.ImportState,
|
||||
&i.ImportReason,
|
||||
&i.ImportDetail,
|
||||
&i.ImportForced,
|
||||
&i.ImportAttempts,
|
||||
&i.ImportUpdatedAt,
|
||||
&i.ImportedAt,
|
||||
&i.ImportedFiles,
|
||||
&i.Destination,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -558,19 +581,26 @@ UPDATE acquisition_settings
|
||||
SET auto_grab = $1,
|
||||
search_interval_hours = $2,
|
||||
allowed_qualities = $3,
|
||||
import_root = $4,
|
||||
updated_at = now()
|
||||
WHERE id = true
|
||||
RETURNING id, auto_grab, search_interval_hours, allowed_qualities, last_pass_at, last_pass, updated_at
|
||||
RETURNING id, auto_grab, search_interval_hours, allowed_qualities, last_pass_at, last_pass, updated_at, import_root
|
||||
`
|
||||
|
||||
type UpdateAcquisitionSettingsParams struct {
|
||||
AutoGrab bool
|
||||
SearchIntervalHours int32
|
||||
AllowedQualities []string
|
||||
ImportRoot string
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateAcquisitionSettings(ctx context.Context, arg UpdateAcquisitionSettingsParams) (AcquisitionSetting, error) {
|
||||
row := q.db.QueryRow(ctx, updateAcquisitionSettings, arg.AutoGrab, arg.SearchIntervalHours, arg.AllowedQualities)
|
||||
row := q.db.QueryRow(ctx, updateAcquisitionSettings,
|
||||
arg.AutoGrab,
|
||||
arg.SearchIntervalHours,
|
||||
arg.AllowedQualities,
|
||||
arg.ImportRoot,
|
||||
)
|
||||
var i AcquisitionSetting
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
@@ -580,6 +610,7 @@ func (q *Queries) UpdateAcquisitionSettings(ctx context.Context, arg UpdateAcqui
|
||||
&i.LastPassAt,
|
||||
&i.LastPass,
|
||||
&i.UpdatedAt,
|
||||
&i.ImportRoot,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
@@ -24,7 +24,13 @@ const countWants = `-- name: CountWants :one
|
||||
SELECT COUNT(*) FILTER (WHERE fulfilled_at IS NULL AND reason <> 'missing')::bigint AS wanted,
|
||||
COUNT(*) FILTER (WHERE fulfilled_at IS NULL AND reason = 'missing')::bigint AS missing,
|
||||
COUNT(*) FILTER (WHERE fulfilled_at IS NOT NULL)::bigint AS held,
|
||||
(SELECT COUNT(*) FROM follows)::bigint AS following
|
||||
(SELECT COUNT(*) FROM follows)::bigint AS following,
|
||||
-- The Wanted view's other tabs (#5522): downloads running, those
|
||||
-- waiting on a person, and releases set aside.
|
||||
(SELECT COUNT(*) FROM grabs WHERE ended_at IS NULL)::bigint AS activity,
|
||||
(SELECT COUNT(*) FROM grabs
|
||||
WHERE ended_at IS NULL AND import_state IN ('review', 'failed'))::bigint AS attention,
|
||||
(SELECT COUNT(*) FROM release_blocks)::bigint AS blocked
|
||||
FROM wants
|
||||
`
|
||||
|
||||
@@ -33,6 +39,9 @@ type CountWantsRow struct {
|
||||
Missing int64
|
||||
Held int64
|
||||
Following int64
|
||||
Activity int64
|
||||
Attention int64
|
||||
Blocked int64
|
||||
}
|
||||
|
||||
func (q *Queries) CountWants(ctx context.Context) (CountWantsRow, error) {
|
||||
@@ -43,6 +52,9 @@ func (q *Queries) CountWants(ctx context.Context) (CountWantsRow, error) {
|
||||
&i.Missing,
|
||||
&i.Held,
|
||||
&i.Following,
|
||||
&i.Activity,
|
||||
&i.Attention,
|
||||
&i.Blocked,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -520,11 +532,18 @@ SELECT w.id, w.release_group_mbid, w.artist_mbid, w.artist_name, w.title, w.reas
|
||||
(SELECT ar.id FROM artists ar WHERE ar.mbid = w.artist_mbid) AS library_artist_id,
|
||||
-- The search schedule's last look (#5521), and the download running.
|
||||
w.searched_at, w.search_outcome, w.search_considered, w.best_release, w.best_verdict, w.search_error,
|
||||
gr.name AS grab_name, gr.grabbed_at, gr.origin AS grab_origin, gr.quality AS grab_quality
|
||||
-- Its latest download, running or ended, and what the import made of
|
||||
-- it (#5522).
|
||||
gr.id AS grab_id, gr.name AS grab_name, gr.grabbed_at, gr.origin AS grab_origin,
|
||||
gr.quality AS grab_quality, gr.ended_at AS grab_ended_at, gr.end_reason AS grab_end_reason,
|
||||
gr.progress AS grab_progress, gr.import_state AS grab_import_state,
|
||||
gr.import_reason AS grab_import_reason, gr.imported_at AS grab_imported_at,
|
||||
gr.imported_files AS grab_imported_files
|
||||
FROM wants w
|
||||
LEFT JOIN users u ON u.id = w.created_by
|
||||
LEFT JOIN mb_release_groups g ON g.mbid = w.release_group_mbid
|
||||
LEFT JOIN grabs gr ON gr.want_id = w.id AND gr.ended_at IS NULL
|
||||
LEFT JOIN grabs gr ON gr.id = (SELECT x.id FROM grabs x WHERE x.want_id = w.id
|
||||
ORDER BY x.ended_at IS NULL DESC, x.grabbed_at DESC LIMIT 1)
|
||||
WHERE CASE $1::text
|
||||
WHEN 'held' THEN w.fulfilled_at IS NOT NULL
|
||||
WHEN 'missing' THEN w.fulfilled_at IS NULL AND w.reason = 'missing'
|
||||
@@ -541,30 +560,38 @@ type ListWantsParams struct {
|
||||
}
|
||||
|
||||
type ListWantsRow struct {
|
||||
ID pgtype.UUID
|
||||
ReleaseGroupMbid string
|
||||
ArtistMbid string
|
||||
ArtistName string
|
||||
Title string
|
||||
Reason string
|
||||
AlbumID pgtype.UUID
|
||||
WantedAt pgtype.Timestamptz
|
||||
FulfilledAt pgtype.Timestamptz
|
||||
PrimaryType string
|
||||
SecondaryTypes []string
|
||||
FirstReleaseDate string
|
||||
RequestedBy *string
|
||||
LibraryArtistID pgtype.UUID
|
||||
SearchedAt pgtype.Timestamptz
|
||||
SearchOutcome string
|
||||
SearchConsidered int32
|
||||
BestRelease string
|
||||
BestVerdict string
|
||||
SearchError string
|
||||
GrabName *string
|
||||
GrabbedAt pgtype.Timestamptz
|
||||
GrabOrigin *string
|
||||
GrabQuality *string
|
||||
ID pgtype.UUID
|
||||
ReleaseGroupMbid string
|
||||
ArtistMbid string
|
||||
ArtistName string
|
||||
Title string
|
||||
Reason string
|
||||
AlbumID pgtype.UUID
|
||||
WantedAt pgtype.Timestamptz
|
||||
FulfilledAt pgtype.Timestamptz
|
||||
PrimaryType string
|
||||
SecondaryTypes []string
|
||||
FirstReleaseDate string
|
||||
RequestedBy *string
|
||||
LibraryArtistID pgtype.UUID
|
||||
SearchedAt pgtype.Timestamptz
|
||||
SearchOutcome string
|
||||
SearchConsidered int32
|
||||
BestRelease string
|
||||
BestVerdict string
|
||||
SearchError string
|
||||
GrabID pgtype.UUID
|
||||
GrabName *string
|
||||
GrabbedAt pgtype.Timestamptz
|
||||
GrabOrigin *string
|
||||
GrabQuality *string
|
||||
GrabEndedAt pgtype.Timestamptz
|
||||
GrabEndReason *string
|
||||
GrabProgress *float32
|
||||
GrabImportState *string
|
||||
GrabImportReason *string
|
||||
GrabImportedAt pgtype.Timestamptz
|
||||
GrabImportedFiles *int32
|
||||
}
|
||||
|
||||
// The Wanted page: open wants (all but missing ones, or only missing ones),
|
||||
@@ -599,10 +626,18 @@ func (q *Queries) ListWants(ctx context.Context, arg ListWantsParams) ([]ListWan
|
||||
&i.BestRelease,
|
||||
&i.BestVerdict,
|
||||
&i.SearchError,
|
||||
&i.GrabID,
|
||||
&i.GrabName,
|
||||
&i.GrabbedAt,
|
||||
&i.GrabOrigin,
|
||||
&i.GrabQuality,
|
||||
&i.GrabEndedAt,
|
||||
&i.GrabEndReason,
|
||||
&i.GrabProgress,
|
||||
&i.GrabImportState,
|
||||
&i.GrabImportReason,
|
||||
&i.GrabImportedAt,
|
||||
&i.GrabImportedFiles,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user