Open buthed010203 opened 1 year ago
Thank you for the suggestion @buthed010203, during early development I came to the same conclusion but the reason why the updatedAt
timestamp isn't used is that it's only relevant for changes to the episode object itself (title, poster, date... etc). If you add/remove/update the files of an episode (when upgrading quality for example) the updatedAt
timestamp will not be changed.
As far as I know, the only way to catch those changes (and therefore be able to tell if the available streams have been updated for an episode) is to scan the whole library. For larger libraries, you can set the refresh_library_on_scan
setting to false
in order to prevent the complete scan from being called every time.
Ah I see, was aware of the setting but would rather keep it on. Perhaps having a thread just for library updates would help make this less of an issue
The scans are already done in a separate thread but if other events occur, they are being queued during the scan and waiting for it to finish. As you suggested, all the library updates could happen in a dedicate thread instead. The only drawback I see with this approach is the fact that the scans sometimes lead to timeout errors due to the large amount of network traffic generated by the library update.
Fair enough
@RemiRigal This could actually be mitigated if autoscan support (plexautolanguages as an autoscan target, would require implementation on autoscan's side as well) was implemented as you would only need to fetch the relevant episode in that case. I'm sure a lot of people with large libraries already use autoscan so they wouldn't need to swap over to it to gain the benefits. What are your thoughts on this?
On another note, it would make sense to only refresh the cache for the relevant tv show library instead of fetching it all again though I don't know how to access the librarySectionID
context attribute to be able to tell what library was just scanned Perhaps we could store the libraries that are currently queued by parsing the message sent when a scan starts? Seems pretty hacky though.
Rebuilding the entire library cache every time an episode is updated is slow, I looked into it and it appears that updated episodes can be fetched the same way as added episodes by changing the
addedAt
toupdatedAt
here: https://github.com/RemiRigal/Plex-Auto-Languages/blob/2de8298504685a5bba600cf19597080945e73dfd/plex_auto_languages/plex_server.py#L67 Not sure if you knew this was possible, it seems to work fine but I haven't done any real testing.Not sure what else the cache is actually used for but it seems that it is pretty much useless now? Would be worth removing to save some small amount of memory.
The
newly_added
andnewly_updated
lists could also be made irrelevant by caching the time of the latest added/updated item and only processing items added/updated after then.