feat(library): exclude configured folders from scanning and analysis
ci / api / api (push) Successful in 56s
ci / contract / contract (сгенерированный код совпадает с openapi.yaml) (push) Successful in 1m23s
ci / db / db (push) Successful in 1m8s
ci / recommender / recommender (push) Failing after 40s
ci / mobile / mobile (Metro-бандл Android) (push) Successful in 1m25s
ci / ts / ts (packages + web) (push) Successful in 7m20s
ci / api / api (push) Successful in 56s
ci / contract / contract (сгенерированный код совпадает с openapi.yaml) (push) Successful in 1m23s
ci / db / db (push) Successful in 1m8s
ci / recommender / recommender (push) Failing after 40s
ci / mobile / mobile (Metro-бандл Android) (push) Successful in 1m25s
ci / ts / ts (packages + web) (push) Successful in 7m20s
This commit is contained in:
1 parent
0dc0384c78
commit
75ae2092ad
23 files changed
+837
-351
No files matched your search
@@ -93,9 +93,13 @@ class Worker:
|
||||
WHERE j.track_id IN (
|
||||
SELECT a.track_id FROM analysis_jobs a
|
||||
JOIN tracks t ON t.id = a.track_id
|
||||
JOIN media_files f ON f.id = t.primary_file_id
|
||||
JOIN library_sources s ON s.id = f.source_id AND s.status = 'mounted'
|
||||
WHERE a.status = 'queued'
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM media_files f JOIN library_sources s ON s.id = f.source_id
|
||||
WHERE f.track_id = t.id AND s.status = 'mounted'
|
||||
AND f.missing_since IS NULL AND f.scan_error IS NULL
|
||||
AND NOT library_path_excluded(f.rel_path, s.excluded_dirs)
|
||||
)
|
||||
ORDER BY a.updated_at
|
||||
LIMIT %s
|
||||
FOR UPDATE OF a SKIP LOCKED)
|
||||
@@ -108,10 +112,17 @@ class Worker:
|
||||
return []
|
||||
files = conn.execute(
|
||||
"""
|
||||
SELECT t.id::text, s.id::text, s.type::text, s.local_path, f.rel_path
|
||||
SELECT t.id::text, f.source_id::text, f.source_type, f.local_path, f.rel_path
|
||||
FROM tracks t
|
||||
JOIN media_files f ON f.id = t.primary_file_id
|
||||
JOIN library_sources s ON s.id = f.source_id
|
||||
CROSS JOIN LATERAL (
|
||||
SELECT s.id AS source_id, s.type::text AS source_type, s.local_path, mf.rel_path
|
||||
FROM media_files mf JOIN library_sources s ON s.id = mf.source_id
|
||||
WHERE mf.track_id = t.id AND s.status = 'mounted'
|
||||
AND mf.missing_since IS NULL AND mf.scan_error IS NULL
|
||||
AND NOT library_path_excluded(mf.rel_path, s.excluded_dirs)
|
||||
ORDER BY (mf.id = t.primary_file_id) DESC NULLS LAST, mf.id
|
||||
LIMIT 1
|
||||
) f
|
||||
WHERE t.id = ANY(%s::uuid[])
|
||||
""",
|
||||
([r[0] for r in rows],),
|
||||
|
||||
@@ -122,6 +122,37 @@ def test_analysis_worker_saves_features(world: dict[str, Any]) -> None:
|
||||
assert row is not None and row[0] == pytest.approx(120.0)
|
||||
|
||||
|
||||
def test_analysis_worker_skips_excluded_folders_and_uses_allowed_copy(world: dict[str, Any]) -> None:
|
||||
worker = Worker(DSN, "/library", "/library-host", 1)
|
||||
blocked, alternative, allowed = world["tracks"][:3]
|
||||
with psycopg.connect(DSN, autocommit=True) as conn:
|
||||
source = conn.execute(
|
||||
"SELECT source_id FROM media_files WHERE track_id = %s", (blocked,)
|
||||
).fetchone()
|
||||
assert source is not None
|
||||
conn.execute(
|
||||
"UPDATE library_sources SET excluded_dirs = ARRAY['Downloads_PumpEars'] WHERE id = %s",
|
||||
(source[0],),
|
||||
)
|
||||
for track, rel in [(blocked, "Downloads_PumpEars/nested/loop.wav"), (alternative, "Downloads_PumpEars/loop.wav"), (allowed, "Downloads_PumpEars-copy/song.flac")]:
|
||||
conn.execute("UPDATE media_files SET rel_path = %s WHERE track_id = %s", (rel, track))
|
||||
conn.execute(
|
||||
"INSERT INTO media_files (id, source_id, rel_path, size_bytes, mtime, format, duration_ms, track_id) "
|
||||
"VALUES (%s, %s, 'Music/allowed-copy.flac', 1, now(), 'flac', 200000, %s)",
|
||||
(uid(), source[0], alternative),
|
||||
)
|
||||
conn.execute(
|
||||
"UPDATE analysis_jobs SET status = 'queued' WHERE track_id = ANY(%s::uuid[])",
|
||||
([blocked, alternative, allowed],),
|
||||
)
|
||||
jobs = {job.track_id: job.path for job in worker.claim(conn, 10000)}
|
||||
assert blocked not in jobs
|
||||
assert jobs[alternative].replace("\\", "/").endswith("/Music/allowed-copy.flac")
|
||||
assert jobs[allowed].replace("\\", "/").endswith("/Downloads_PumpEars-copy/song.flac")
|
||||
row = conn.execute("SELECT attempts, status FROM analysis_jobs WHERE track_id = %s", (blocked,)).fetchone()
|
||||
assert row == (0, 'queued'), "excluded files must not consume retry attempts"
|
||||
|
||||
|
||||
def test_training_and_wave_queries(world: dict[str, Any]) -> None:
|
||||
with psycopg.connect(DSN) as conn:
|
||||
assert len(load_interactions(conn)) >= 60
|
||||
|
||||
Reference in new issue
Block a user