feat(library): remove a track from the library without deleting the file
RemoveFromLibrary deletes the audio_files rows the way the scan's own orphan cleanup does and records each path in excluded_paths. The exclusion is not an enhancement: without it the next scan finds the file, sees no row and imports it again, so the button undoes itself. The soft scan compares files on disk against rows in the database, so surveyAudioFiles and countAudioFiles both take the exclusion set — otherwise an excluded path makes the two disagree forever and queues a full scan on every launch. Deleting a row cascades to queue_tracks, so the removal calls the same CompactQueue hook RemoveLibrary does. Also lands the requested badge: library-status-indicator is a button again where it can act, utils/library-status.ts states once what owning and wanting mean, and the long-declared queued state finally has a producer. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UDCbcCZQepnpSQYJ6SxxZm
This commit is contained in:
@@ -343,3 +343,7 @@ JOIN audio_files af ON af.recording_id = r.id
|
||||
WHERE r.mbid IN (sqlc.slice('mbids'))
|
||||
AND af.library_id = ?
|
||||
ORDER BY af.file_path;
|
||||
|
||||
-- name: GetAudioFilesByPaths :many
|
||||
SELECT id, library_id, file_path, group_key FROM audio_files
|
||||
WHERE file_path IN (sqlc.slice('paths'));
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
-- name: ExcludePath :exec
|
||||
INSERT INTO excluded_paths (library_id, file_path)
|
||||
VALUES (?, ?)
|
||||
ON CONFLICT(library_id, file_path) DO NOTHING;
|
||||
|
||||
-- name: GetExcludedPathsByLibrary :many
|
||||
SELECT file_path FROM excluded_paths
|
||||
WHERE library_id = ?;
|
||||
|
||||
-- name: CountExcludedPathsByLibrary :one
|
||||
SELECT COUNT(*) FROM excluded_paths
|
||||
WHERE library_id = ?;
|
||||
|
||||
-- name: ClearExcludedPaths :exec
|
||||
DELETE FROM excluded_paths;
|
||||
@@ -0,0 +1,25 @@
|
||||
-- Paths the user has removed from the library, which the scanner must
|
||||
-- not import again.
|
||||
--
|
||||
-- "Remove from library" deletes the audio_files row and leaves the file
|
||||
-- on disk. Without this table the next scan finds the file, sees no
|
||||
-- row for it, and imports it again — so the exclusion is not an
|
||||
-- enhancement, it is what makes the operation mean anything.
|
||||
--
|
||||
-- A row is keyed by (library_id, file_path) rather than by audio_file
|
||||
-- id, because the row it names has just been deleted. ON DELETE
|
||||
-- CASCADE from libraries means removing a library takes its exclusions
|
||||
-- with it; a full rescan clears the table outright, which is the only
|
||||
-- way back for a path removed by mistake until there is a UI for it.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS excluded_paths (
|
||||
id INTEGER PRIMARY KEY,
|
||||
library_id INTEGER NOT NULL,
|
||||
file_path TEXT NOT NULL,
|
||||
excluded_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE(library_id, file_path),
|
||||
FOREIGN KEY(library_id) REFERENCES libraries(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_excluded_paths_library
|
||||
ON excluded_paths(library_id);
|
||||
@@ -648,6 +648,56 @@ func (q *Queries) GetAudioFilesByLibrary(ctx context.Context, libraryID int64) (
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getAudioFilesByPaths = `-- name: GetAudioFilesByPaths :many
|
||||
SELECT id, library_id, file_path, group_key FROM audio_files
|
||||
WHERE file_path IN (/*SLICE:paths*/?)
|
||||
`
|
||||
|
||||
type GetAudioFilesByPathsRow struct {
|
||||
ID int64
|
||||
LibraryID int64
|
||||
FilePath string
|
||||
GroupKey string
|
||||
}
|
||||
|
||||
func (q *Queries) GetAudioFilesByPaths(ctx context.Context, paths []string) ([]GetAudioFilesByPathsRow, error) {
|
||||
query := getAudioFilesByPaths
|
||||
var queryParams []interface{}
|
||||
if len(paths) > 0 {
|
||||
for _, v := range paths {
|
||||
queryParams = append(queryParams, v)
|
||||
}
|
||||
query = strings.Replace(query, "/*SLICE:paths*/?", strings.Repeat(",?", len(paths))[1:], 1)
|
||||
} else {
|
||||
query = strings.Replace(query, "/*SLICE:paths*/?", "NULL", 1)
|
||||
}
|
||||
rows, err := q.db.QueryContext(ctx, query, queryParams...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetAudioFilesByPathsRow
|
||||
for rows.Next() {
|
||||
var i GetAudioFilesByPathsRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.LibraryID,
|
||||
&i.FilePath,
|
||||
&i.GroupKey,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getAudioFilesByReleaseGroup = `-- name: GetAudioFilesByReleaseGroup :many
|
||||
SELECT
|
||||
af.file_path,
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: excluded_paths.sql
|
||||
|
||||
package sqlcgen
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const clearExcludedPaths = `-- name: ClearExcludedPaths :exec
|
||||
DELETE FROM excluded_paths
|
||||
`
|
||||
|
||||
func (q *Queries) ClearExcludedPaths(ctx context.Context) error {
|
||||
_, err := q.db.ExecContext(ctx, clearExcludedPaths)
|
||||
return err
|
||||
}
|
||||
|
||||
const countExcludedPathsByLibrary = `-- name: CountExcludedPathsByLibrary :one
|
||||
SELECT COUNT(*) FROM excluded_paths
|
||||
WHERE library_id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) CountExcludedPathsByLibrary(ctx context.Context, libraryID int64) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, countExcludedPathsByLibrary, libraryID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const excludePath = `-- name: ExcludePath :exec
|
||||
INSERT INTO excluded_paths (library_id, file_path)
|
||||
VALUES (?, ?)
|
||||
ON CONFLICT(library_id, file_path) DO NOTHING
|
||||
`
|
||||
|
||||
type ExcludePathParams struct {
|
||||
LibraryID int64
|
||||
FilePath string
|
||||
}
|
||||
|
||||
func (q *Queries) ExcludePath(ctx context.Context, arg ExcludePathParams) error {
|
||||
_, err := q.db.ExecContext(ctx, excludePath, arg.LibraryID, arg.FilePath)
|
||||
return err
|
||||
}
|
||||
|
||||
const getExcludedPathsByLibrary = `-- name: GetExcludedPathsByLibrary :many
|
||||
SELECT file_path FROM excluded_paths
|
||||
WHERE library_id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetExcludedPathsByLibrary(ctx context.Context, libraryID int64) ([]string, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getExcludedPathsByLibrary, libraryID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []string
|
||||
for rows.Next() {
|
||||
var file_path string
|
||||
if err := rows.Scan(&file_path); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, file_path)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
@@ -139,6 +139,13 @@ type DownloadRequest struct {
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type ExcludedPath struct {
|
||||
ID int64
|
||||
LibraryID int64
|
||||
FilePath string
|
||||
ExcludedAt time.Time
|
||||
}
|
||||
|
||||
type ExploreChampionFt struct {
|
||||
Title string
|
||||
ArtistName string
|
||||
|
||||
Reference in New Issue
Block a user