Repository navigation
Delete old related info in bulk as late as possible in UpdateOrInsertItems - #17555
Merged
Merged
Conversation
Makes the test O(log n)
Replace the O(n²) array .First scan with a dictionary lookup
Contributor
Jellyfin API (v 12.0.0)ResultNo differences. Specifications are equivalent |
IDisposable
force-pushed
the
fix/reorder-update-items
branch
from
August 6, 2026 05:11
d52a518 to
9c229d2
Compare
This makes the deletion of BaseItemProviders, BaseItemImageInfos, and BaseItemMetadataFields happen in batch as a contiguous block so the lock isn't held across items, just before the bulk SaveChanges.
IDisposable
force-pushed
the
fix/reorder-update-items
branch
from
August 6, 2026 06:00
9c229d2 to
1c5c95a
Compare
|
Shadowghost
approved these changes
Aug 6, 2026
JPVenson
approved these changes
Aug 6, 2026
crobibero
approved these changes
Aug 8, 2026
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.
In UpdateOrInsertItems, the deletion of the related items (BaseItemProviders, BaseItemImageInfos, BaseItemMetadataFields) was being done item-by-item early in the computation of what will be saved. This means we're doing 3n SQL calls to delete each related table's rows. Additionally this takes a write lock out on all the tables touched very early in the processing.
By moving the related rows deletion to just before the SaveChanges call, we can delete all the rows in the related tables with just 3 calls (in bulk across all the modified items), and will take out the lock at the last possible moment.
NOTE
This stacks on top of PR #17554 because it uses the existingItems hashset.
Changes
Added unit test to ensure the same set of rows is DELETE and INSERT as before.
Use bulk deletion of related items using WhereOneOrMany() against all the IDs instead of Where() on each item
Move the deletion of the related items to just before the SaveChanges to hold the lock for far less time.
Code assistance
Claude Code to build and validate the unit test
Issues
Various places where updating a large number of items at once (for example in Scheduled Task sweeps) results in Database/Table Locked errors.