fix: harden scans, downloads, sync and radio edge cases
Scanner and library: - Keep the last library when a configured folder cannot be walked; the previous code deleted every song, cascading away mood seeds and progress. - Re-adding a file now clears its tombstone, and a re-deletion refreshes the timestamp instead of keeping the old one. - Tombstone timestamps are unique per row, and delta pages continue from the older of the song/tombstone page ends. - Snapshot pagination accepts a stable revision for later pages so songs inserted mid-sync are not skipped forever. - Reject "%" and "_" searches that normalize to an empty LIKE needle. Downloads and discovery: - Download promotion uses the deterministic path id, one folder per track so covers do not overwrite each other, removes failed promotions, and restarts the scan after a running one finishes. - Stale downloading jobs are recovered; reject cancels queued/in-flight jobs; markDone only owns downloading rows; rejecting no longer seeds the track. - Reuse an already completed download of the same video for another mood. - yt-dlp stdout and stderr are separated, empty discovery results no longer prune undecided recommendations, and filenames are capped by UTF-8 bytes. API and data: - Malformed or missing JSON returns 400 instead of 500; optional session bodies use receiveNullable. - Playback events must belong to the session, known song and open session. - Radio refills the candidate pool after recent-song pruning. - Seed percent is required in MoodRepository.update. - Normalize legacy V4 liked/downloaded recommendation states before V5, with an upgrade regression test. CI: check out without persisting credentials and require tests before chart publishing.
This commit is contained in:
1 parent
c75f2971b4
commit
4be502bb4e
23 files changed
+705
-66
No files matched your search
@@ -2,6 +2,9 @@ package win.taptap.musicmanager.db
|
||||
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.sql.DriverManager
|
||||
import org.flywaydb.core.Flyway
|
||||
import org.flywaydb.core.api.MigrationVersion
|
||||
import java.time.Instant
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
@@ -43,6 +46,58 @@ class DatabaseFactoryTest {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun `upgrades legacy liked and downloaded recommendations`() {
|
||||
val config = appConfig()
|
||||
Files.createDirectories(config.dataDir)
|
||||
val url = "jdbc:sqlite:${config.databasePath.toAbsolutePath()}"
|
||||
|
||||
Flyway.configure()
|
||||
.dataSource(url, null, null)
|
||||
.locations("classpath:db/migration")
|
||||
.target(MigrationVersion.fromVersion("4"))
|
||||
.load()
|
||||
.migrate()
|
||||
|
||||
DriverManager.getConnection(url).use { connection ->
|
||||
connection.createStatement().use { statement ->
|
||||
statement.executeUpdate(
|
||||
"INSERT INTO users (name, is_admin, updated_at) VALUES ('alice', 1, 'now')",
|
||||
)
|
||||
statement.executeUpdate(
|
||||
"INSERT INTO playlists (id, owner, name, created_at, changed_at) " +
|
||||
"VALUES ('pl-1', 'alice', 'Mood', 'now', 'now')",
|
||||
)
|
||||
statement.executeUpdate(
|
||||
"INSERT INTO moods (playlist_id) VALUES ('pl-1')",
|
||||
)
|
||||
statement.executeUpdate(
|
||||
"INSERT INTO mood_recommendations " +
|
||||
"(playlist_id, video_id, title, artist, state, first_seen, last_seen) " +
|
||||
"VALUES ('pl-1', 'v-1', 'Title', 'Artist', 'liked', 'now', 'now')",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val db = DatabaseFactory.connect(config)
|
||||
try {
|
||||
val state = db.dataSource.connection.use { connection ->
|
||||
connection.createStatement().use { statement ->
|
||||
statement.executeQuery(
|
||||
"SELECT state FROM mood_recommendations WHERE video_id = 'v-1'",
|
||||
).use { result ->
|
||||
result.next()
|
||||
result.getString(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
assertEquals("new", state)
|
||||
} finally {
|
||||
db.close()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `syncs folders and users idempotently`() {
|
||||
val db = DatabaseFactory.connect(appConfig())
|
||||
|
||||
Reference in new issue
Block a user