-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix library files inconsistencies #2773
Fix library files inconsistencies #2773
Conversation
I also added a fix to #2767, since it touches the same areas of code. In a nutshell, I fixed the library item matching logic, in both the watcher and the library scan code paths. Up until now, it was only able to find an existing library item if it had the same ino as the detected change. I changed the logic to also match between an item's ino and another item's library file inos (and the other way round). Again, I tested this extensively trying to move an audio file around, with watcher disabled and library scans, and with watcher enabled. This seems to work well now. |
Just a couple of meta comments on all of this:
|
The functions that are grouping files into library item paths is something I've wanted to refactor for a while so they can share the same function. |
…terate through json objects comparing inodes
sequelize.where(sequelize.literal('(SELECT count(*) FROM json_each(libraryFiles) WHERE json_valid(json_each.value) AND json_each.value->>"$.ino" = :inode)'), { | ||
[sequelize.Op.gt]: 0 | ||
}) | ||
], { | ||
inode: ino | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some file systems have inode values that are only a few digits long so I added this additional query that uses sqlite json functions. Unfortunately this is an extra query and is sqlite specific but in Sequelize v7 they are adding support for handling JSON queries.
I tested a lot of situations and it is working for all the cases you solved for. I found an existing bug with the scanner that I overlooked when I switched everything to sqlite. The bug can be reproduced by..
I'm not sure how to solve for that yet. This logic is getting complex as you mentioned. |
Regarding the bug, I looked at this "first pass" code, and I must admit I don't have clear understanding of what this code is supposed to do, and why... the comment doesn't really help. I'll try to read it more carefully, but if you have a moment, I'd appreciate a short exaplanation. |
Yeah this is a mess just looking at it again. I'll take a stab at cleaning up that function |
+1 |
Fixes #2686
After some further investigation, it looks like the code already covers Audio files media updates for modified files, so what I ended up doing was the following:
To test this, I did a lot of moving of directries between different folders (with audio/ebooks/covers) in the same library ) with watcher on and off (and running library scans when watcher was off). Now everything seems to be working without crashes or errors, and the database records look fine after each move. I'd like to write unit tests, but the code is so complicated that I need to wrap my head around how to do it properly.
Also, I still need to write a db migration script to fix existing corrup records, but I think it's important to check in the logic fixes first because of the nasty crashes and corruptions the current code can potentially create.