Optimize Jellyfin API Requests#236
Open
MattKercher wants to merge 24 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Jellyfin
/Itemsendpoint, particularly on Jellyfin 10.11.x, can be extremely slow, especially on servers with a ton of music tracks. This PR optimizes requests by reducing round trips to the server and by reducing the amount of background threads. From my testing, requests now take about 25% of the time that they used to for my Jellyfin server. Honestly, this started as a pretty small change and ended up expanding out into a bunch of changes, so I'm really sorry if the PR is kind of large. For an exhaustive list of changes:Jellyfin-Specific Integration Changes:
liteboolean argument to exclude unnecessary information that's not used by rows/buttons.self._bulk_verifyfunction to iterate through API response lists and send each response object to the verify functions to write them toloaded_modelsinstead of relying on buttons/rows to fetch the information themselves.getAlbumList()/getRandomSongs()/getArtists()/getPlaylists()uses this function to write their response lists toloaded_modelsinstead of doing it manually.search()function used to completely rely on the buttons/rows calling their corresponding verify function despite having already retrieved the item lists from the API, so now search writes its response lists to loaded_models usingbulk_verifysimilar to the methods above.verifyArtist()function./Artist/AlbumArtistendpoint for fetching artists, as the/Itemsendpoint returns artist folders instead of AlbumArtists.Other Integration Changes:
self.threadsand switches Jellyfin and Navidrome to use it. This restricts how many background threads can be spawned to at once to 30 and queues any additional threads in order to prevent hammering the server with API requests and to prevent the network connection pool from filling up.requests.Sessionis apparently not thread safe, soself.sessionnow returns a new session object whenever it's called.self.sessionuses thewithoperator now to ensure that the session is properly closed.Album Button:
set_action_name()is called from theupdate_artist_id()instead of being set in the associated Blueprint file. I'm not sure if this is the best approach, but it seemed to fix the problem.I tried to test as thoroughly as possible, but since I don't have a Navidrome instance I had to test against the Navidrome demo. Hopefully that was sufficient, since I didn't substantially change the Navidrome integration.