mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-07-25 06:03:37 +03:00
[PR #14557] [MERGED] Refactor query from EXISTS to JOIN to avoid API timeouts with large libraries #14031
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/jellyfin/jellyfin/pull/14557
Author: @evan314159
Created: 8/1/2025
Status: ✅ Merged
Merged: 8/11/2025
Merged by: @crobibero
Base:
master← Head:query-optimisation📝 Commits (2)
9afa063Refactor query from EXISTS to JOIN to avoid API timeouts with large librariesa3d022dMerge branch 'jellyfin:master' into query-optimisation📊 Changes
1 file changed (+10 additions, -5 deletions)
View changed files
📝
Jellyfin.Server.Implementations/Item/BaseItemRepository.cs(+10 -5)📄 Description
Changes
This change refactors a critical query used by APIs like /Artists to replace nested EXISTS with explicit JOINs. This enables index usage and eliminates timeouts when querying large libraries.
A client like Manet requesting /Artists with limit = 200 could not complete library sync due to SQL command timeout because the query could not use indexes. With this change, a SQL query simulating /Artists retrieving all artists ran on my system in 0.173 ms, and Manet is able to complete full library sync successfully. /Artists performs OK overall even with limit = 0 following this change, while other APIs remain slow due to DTO overhead but at least all API used by Manet complete execution now where they previously could not.
My library is approximately 3200 artists, 2500 albums, 41.5k tracks. I am not sure at what point a library is large enough to cause API timeouts, but another user with a large library confirmed my experience with Manet in the developer chat.
I reviewed other nested EXISTS queries; some showed minor improvements, but none matched the significant benefit of this change. In some cases, performance even regressed.
Given the complexity of the original and improved queries, it is not obvious they produce identical results. I verified with Claude and ChatGPT, and have attached an explanation from ChatGPT.
Original version:
Improved version:
Logical equivalence rationale:
Issues
Fixes API timeouts for large libraries with Manet and similar apps, no issue #.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.