make -1 all
All checks were successful
/ release (push) Successful in 30s

This commit is contained in:
speatzle 2024-10-08 12:44:23 +02:00
parent b6c22df6f1
commit cee5353b54
3 changed files with 12 additions and 9 deletions

View file

@ -91,7 +91,7 @@ func generateStats(ctx context.Context, library_id string) ([]ChartData, error)
rows, err := db.Query(ctx,
`SELECT COALESCE(jsonb_path_query_first(ffprobe_data, '$.streams[*] ? (@.codec_type == "video") ? (@.disposition.attached_pic == 0).codec_name')::text, 'Unknown') AS name, COUNT(*) AS value
FROM files
WHERE ffprobe_data IS NOT NULL AND ($1 = "" OR library_id = $1)
WHERE ffprobe_data IS NOT NULL AND ($1 = -1 OR library_id = $1)
GROUP BY 1;`, library_id)
if err != nil {
return nil, fmt.Errorf("Query Codecs: %w", err)
@ -113,7 +113,7 @@ func generateStats(ctx context.Context, library_id string) ([]ChartData, error)
rows, err = db.Query(ctx,
`SELECT COALESCE(jsonb_path_query_first(ffprobe_data, '$.streams[*] ? (@.codec_type == "video") ? (@.disposition.attached_pic == 0).width')::text, 'Unknown') AS name, COUNT(*) AS value
FROM files
WHERE ffprobe_data IS NOT NULL AND ($1 = "" OR library_id = $1)
WHERE ffprobe_data IS NOT NULL AND ($1 = -1 OR library_id = $1)
GROUP BY 1;`, library_id)
if err != nil {
return nil, fmt.Errorf("Query Resolution: %w", err)
@ -135,7 +135,7 @@ func generateStats(ctx context.Context, library_id string) ([]ChartData, error)
rows, err = db.Query(ctx,
`SELECT COALESCE(jsonb_path_query_first(ffprobe_data, '$.format.format_name')::text, 'Unknown') AS name, COUNT(*) AS value
FROM files
WHERE ffprobe_data IS NOT NULL AND ($1 = "" OR library_id = $1)
WHERE ffprobe_data IS NOT NULL AND ($1 = -1 OR library_id = $1)
GROUP BY 1;`, library_id)
if err != nil {
return nil, fmt.Errorf("Query Container: %w", err)
@ -156,7 +156,7 @@ func generateStats(ctx context.Context, library_id string) ([]ChartData, error)
rows, err = db.Query(ctx,
`SELECT health AS id, COUNT(*) AS value
FROM files WHERE ($1 = "" OR library_id = $1)
FROM files WHERE ($1 = -1 OR library_id = $1)
GROUP BY 1;`, library_id)
if err != nil {
return nil, fmt.Errorf("Query Health: %w", err)
@ -177,7 +177,7 @@ func generateStats(ctx context.Context, library_id string) ([]ChartData, error)
rows, err = db.Query(ctx,
`SELECT transcode AS id, COUNT(*) AS value
FROM files WHERE ($1 = "" OR library_id = $1)
FROM files WHERE ($1 = -1 OR library_id = $1)
GROUP BY 1;`, library_id)
if err != nil {
return nil, fmt.Errorf("Query Transcode: %w", err)
@ -199,7 +199,7 @@ func generateStats(ctx context.Context, library_id string) ([]ChartData, error)
rows, err = db.Query(ctx,
`SELECT tasks.status AS id, COUNT(*) AS value
FROM tasks INNER JOIN files ON files.id = tasks.file_id
WHERE ($1 = "" OR files.library_id = $1)
WHERE ($1 = -1 OR files.library_id = $1)
GROUP BY 1;`, library_id)
if err != nil {
return nil, fmt.Errorf("Query Task Status: %w", err)
@ -227,7 +227,7 @@ func generateStats(ctx context.Context, library_id string) ([]ChartData, error)
rows, err = db.Query(ctx,
`SELECT date_trunc('day', tasks.updated_at) date, tasks.status, COUNT(*) AS count
FROM tasks INNER JOIN files ON files.id = tasks.file_id
WHERE ($1 = "" OR files.library_id = $1) AND tasks.updated_at > tasks.current_date - 7 AND (tasks.status = $2 OR tasks.status = $3)
WHERE ($1 = -1 OR files.library_id = $1) AND tasks.updated_at > tasks.current_date - 7 AND (tasks.status = $2 OR tasks.status = $3)
GROUP BY 1,2
ORDER BY date;`, library_id, constants.TASK_STATUS_SUCCESS, constants.TASK_STATUS_FAILED)
if err != nil {
@ -293,6 +293,9 @@ func generateStats(ctx context.Context, library_id string) ([]ChartData, error)
func handleStats(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
if id == "" {
id = "-1"
}
data, err := generateStats(r.Context(), id)
if err != nil {

View file

@ -1,5 +1,5 @@
function setLibrary(library_id) {
if (library_id === "") {
if (library_id == "-1") {
} else {
window.location.href = "/stats";
}

View file

@ -2,7 +2,7 @@
<h2>Stats</h2>
<label for="library">Library:</label>
<select id="library" name="library" onchange="setLibrary(this.value)" class="short-button">
<option {{if eq .SelectedLibrary "" }} selected {{end}}value="">ALL</option>
<option {{if eq .SelectedLibrary -1 }} selected {{end}}value="-1">ALL</option>
{{range $l := .Libraries}}
<option {{if eq .SelectedLibrary $l.ID }} selected {{end}}value="{{$l.ID}}">{{$l.Name}}</option>
{{end}}