fix: added batch collection adding of media for Jellyfin#2494
Conversation
|
I didn't yet go into If we redo these operations to use a bulk call to the media server, the other operations will also have do be done in bulk before/after this call, so I wanted to ask for input first. Also if the MediaServerFeature approach is not good, let me know how to change it. |
This comment was marked as resolved.
This comment was marked as resolved.
4be1841 to
be9571c
Compare
| @@ -277,6 +286,15 @@ export class PlexAdapterService implements IMediaServerService { | |||
| } | |||
| } | |||
|
|
|||
| async removeBatchFromCollection( | |||
| collectionId: string, | |||
| itemIds: string[], | |||
| ): Promise<void> { | |||
| for (const itemId of itemIds) { | |||
| await this.removeFromCollection(collectionId, itemId); | |||
| } | |||
| } | |||
|
|
|||
There was a problem hiding this comment.
Right now the batch methods throw in the Plex adapter on any failed operation, I don't know if we should do this another way
There was a problem hiding this comment.
This should be fixed now.
Instead of throwing on the first Plex failure, the batch methods now return the failed item IDs. That lets the collection service handle partial success properly, while still treating Plex 404 removes as success and Jellyfin failures as all-or-nothing.
- Guard against empty arrays in all batch methods (both adapters + service layer) - Plex batch: continue on per-item failures instead of aborting the whole batch - Plex batch remove: restore 404 tolerance (item already gone is not an error) - Only pass itemIds to createCollection when COLLECTION_CREATION_WITH_ITEMS is supported - Improve error messages to include the specific mediaServerId that failed - Fix contract doc: reference feature flag instead of hardcoding "Jellyfin only"
|
Hey, nice work on the batch approach - using Jellyfin's native multi-id support is the right call. I went ahead and pushed a commit with some hardening fixes: What I changed
|
PR #2494 - fix: added batch collection adding of media for Jellyfin - Batch collection add/remove using Jellyfin's native multi-id API support - New COLLECTION_CREATION_WITH_ITEMS feature flag to skip redundant resync - Plex fallback via sequential calls with per-item error resilience - Empty array guards on all batch methods - Restored 404 tolerance on Plex batch remove - itemIds only passed to createCollection when feature is supported
|
Tightened the batch methods a bit — they now return failed IDs instead of assuming success, so the service layer only writes DB rows for items that actually landed on the server. Also wired up create-with-items properly: Jellyfin gets items at creation time, Plex and manual collections fall back to the sequential add path. |
PR #2494 - fix: added batch collection adding of media for Jellyfin - Batch collection add/remove using Jellyfin's native multi-id API support - New COLLECTION_CREATION_WITH_ITEMS feature flag to skip redundant resync - Batch methods return failed IDs so the service layer only persists DB rows for items that actually landed on the server - Create-with-items wired into createCollection: Jellyfin gets items at creation time, Plex and manual collections fall back to the sequential add path - Plex sequential fallback with per-item error handling and 404 tolerance on remove
|
Tested, and works beautifully! AddRemoveMaintainerr Jellyfin Result: No locks at all in the Jellyfin logs! 🥳 |
|
🎉 This PR is included in version 3.2.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
…ellyfin Fixes a regression introduced in v3.2.0 where rule execution would crash with "Cannot read properties of undefined (reading 'id')" for Jellyfin users. The COLLECTION_CREATION_WITH_ITEMS optimisation (PR #2494, fixing #2489) attempted to create a Jellyfin collection with all existing item IDs in a single atomic API call. If Jellyfin rejected any ID (e.g. stale/unavailable media), the entire createCollection call threw, addToCollectionInternal returned undefined, and the caller in rule-executor then accessed collection.id on that undefined — crashing the rule run for every affected collection. The original lag problem that motivated PR #2494 was independently solved by PR #2511 (issue #2493), so the optimisation no longer provides any benefit. Fix: - Remove itemIds from all createCollection call sites; collections are always created empty and items are added via the existing addBatchToCollection path - Remove the COLLECTION_CREATION_WITH_ITEMS feature flag (enum, constants, CreateCollectionParams.itemIds) as it is now unused - Add null guards in addToCollectionWithResolvedLink and removeFromCollectionWithResolvedLink to prevent crashes if collection creation fails for any other reason - Add collection && guard in rule-executor before the remove block for the same defensive reason - Update tests to reflect the new invariant: createCollection never receives itemIds regardless of media server type Removed implementation introduced by: PR #2494 PR #2494 fixed: issue #2489 Related later Jellyfin collection creation fix: PR #2511 for issue #2493
Description & Design
This fixes potential Jellyfin errors caused by collection mutations requested by Maintainerr in quick succession.
The solution implemented here is taking advantage of Jellyfin's support for sending multiple media ids at the same time in one collection creation/media addition/media removal request.
The new batch methods are exposed in the media server abstractization and leverage the support described above for the Jellyfin implementation, and makes sequential calls in the Plex implementation.
This PR introduces a new
MediaServerFeature:COLLECTION_CREATION_WITH_ITEMS, which represents whether the Media Server supports sending a list of media ids to be automatically added on collection creation.Related issue
Fixes #2489
AI-Assisted Development
I used Copilot for tab autocomplete in a few parts of the code, but I read each suggestion before accepting it. Did not have the AI do any complex/agent work.
Checklist
How to test
Syncing ${collectionMedia.length} existing items to newly created media server collectionmessage will not be displayed, but the collection will be recreated properly with all the items in Jellyfin.