mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-01-23 23:20:51 +01:00
[PR #14557] [MERGED] Refactor query from EXISTS to JOIN to avoid API timeouts with large libraries #13852
Labels
No labels
area:database
awaiting-feedback
backend
blocked
breaking change: web api
bug
build
ci
confirmed
discussion needed
dotnet future
downstream
duplicate
EFjellyfin.db
enhancement
feature
future
github-actions
good first issue
hdr
help wanted
invalid
investigation
librarydb
live-tv
lyrics
media playback
music
needs testing
nuget
performance
platform
pull-request
question
regression
release critical
requires-web
roadmap
security
security
stale
support
syncplay
ui & ux
upstream
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: starred/jellyfin#13852
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
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.