taiga
taiga copied to clipboard
Move scanning for available episodes to a separate thread
Not sure if that would cause issues with other parts of the program, but maybe it'd be possible to have the scanning for available episodes run in a thread that's separate from the GUI thread? In my case (and I think I might not be the only one) I have all my archived shows on my NAS which obviously runs HDDs. Those get put into standby mode when they're not being acccessed for a certain amount of time and thus need like 10-15 seconds to fully wake up. That wake-up time combined with a semi big library causes the application to be completely unusable for up to half a minute. That might not sound like much but at least to me it's always an annoyance since I open and close Taiga several times a day.
I would also be extremely thankful for asynchronous file scanning - my HDDs are pretty big so the initial scan on startup always takes a notable amount of time during which the program is frozen. There's other things in Taiga that would benefit from asynchronous execution too (like making HTTP requests - initial requests after a while, like increasing watched episode count, also freeze up the program for a while every time) for that matter.
I'd like to implement this - the idea seems simple enough.
- Create a class inheriting from win::Thread that runs the scan in its
ThreadProc
- Replace the
ScanAvailableEpisodes
calls with a new function that starts the thread (question: How can I best pass parameters? Maybe fields in the Scanner class?) - Add some locking mechanism (doesn't make sense to have multiple scans running at the same time) - still need to look this up
- Test a lot
I'm a bit of a C++ noob but I know my way around other languages and VS is pretty good at helping with the basics, so I think I'll open a PR once I feel comfortable with the code.
Can anyone help me with the question in point 2?
Hey @FreezyLemon, thanks for your interest.
While spawning a new thread from the scanner is simple enough, you will quickly realize that the things it does is far from being thread safe. That's the main reason I haven't touched this for so long: Taiga wasn't designed with multithreading in mind, so starting threads without concern is a recipe for disaster.
My plan was to devise and implement an event system first, before tackling this feature and some others. But let me know if you have something else in mind, after taking a look at the code.
Hi @erengy, you're right. I've been reading the code for a bit and implementing this idea in a truly thread-safe way seems like it would need a lot of work in other places (like you mentioned).
I think I'll take another look around the repo :)