WIP: Refactor the IDatabase calls to write directly to the database #271
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "268---refactor-the-idatabase-calls-to-write-directly-to-the-database"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #268
Step 1: get rid of pre-commit - upon failure reload database. This introduces extra writes which are to be resolved by being more selective about what is to be written.
To do:
Redo the_and
update methods to not take arbitrary closures but sort the parent collection.Figure out how best to make targeted updates to the DB - updating only the values that need updating is better.Also contemplate replacing all searches through get_collection with dedicated queries -> will no longer need to keep collection in memory
Must still ensure that all items in the library are written into the database (including any changes). At the moment the database is dumped in full after initial startup.
Rely on the database to do this logic. After all, it's meant to be clever and efficient. Hide this logic within
save
and make the SQL queries clever.Remember to add an integration test which will have a database with new items that should be added/modified in the test.
Options so far:
Expect few replacements and few inserts in general
Working example
This is better than using
!=
and<>
as it will correctly handlesort
being NULL in the destination tableSo the rusqlite query should be:
Following Reddit thread, this works too
Thorny problem: could have acquired lib_id in merge, but lib_id is used in UNIQUE clause. Previously this was not a problem since all tables were dropped and rewritten.
Potential solution: downgrade mbid back to non-id and introduce a DB-id which is guaranteed to exist for every item in the DB. Then the DB id will be the unique constraint just like lib_id or singleton+title is for library albums or name for artists. MBID was being used as a proxy for DB id but this fails when a DB id needs to exist and none exists.
Use the DB to assign the DB id just like the library assigns lib IDs. Tough this will require querying the DB after a save.
Don't need one for artists. Beets does not assign IDs to artists and generally in case of a name clash, the more famous band wins and the other disambiguates.
Use the fact that SQL NULL values are considered different in a UNIQUE constraint (https://stackoverflow.com/questions/22699409/sqlite-null-and-unique)
Solution: converge on a unique database ID. Every item in the collection MUST have a database ID and this will be the only unique identifier. Everything else: name/title, lib id will get relegated to info metadata.
By the end IDatabase should not have
save
. Every insert/update should be explicit. (ideally - it might be easier to just leave it for now).Remember to move artist sort from name to meta
Q: What sets info apart from the rest of meta?
Options
Also rebrand TrackId to TrackTitle
Checkout
From your project repository, check out a new branch and test the changes.