[PR #15071] Fix backdrop image ordering regression in EF Core migration #14050

Open
opened 2025-12-22 10:17:01 +01:00 by backuprepo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/jellyfin/jellyfin/pull/15071
Author: @seeyabye
Created: 10/21/2025
Status: 🔄 Open

Base: release-10.11.zHead: fix-backdrop-image-ordering


📝 Commits (10+)

  • c8b8cbf Fix backdrop image ordering regression after EF Core migration by implementing runtime sorting that matches LocalImageProvider discovery order
  • f49e632 Add database-level SortOrder for backdrop images
  • 989cb3c Improve PopulateImageSortOrder migration with async and memory efficiency
  • 2b4942d Changed composite index to include ImageType
  • 65160f2 Prepoluate SortOrder before correction
  • ca5443e Changed SaveImage logic
  • ddb641e Fixed SortOrder not being populated on new scans
  • 6385474 Cleanup
  • e90321a Fixed SortOrder for Web Uploads
  • 1ec2815 Fixed AddImage's ordering to ensure consistency

📊 Changes

12 files changed (+2380 additions, -30 deletions)

View changed files

📝 Jellyfin.Server.Implementations/Item/BaseItemRepository.cs (+123 -8)
Jellyfin.Server/Migrations/Routines/PopulateImageSortOrder.cs (+253 -0)
📝 MediaBrowser.Controller/Entities/BaseItem.cs (+95 -19)
📝 MediaBrowser.Controller/Entities/ItemImageInfo.cs (+7 -0)
📝 MediaBrowser.Controller/Persistence/IItemRepository.cs (+10 -0)
MediaBrowser.Controller/Utilities/ImageOrderingUtilities.cs (+53 -0)
📝 MediaBrowser.LocalMetadata/Images/LocalImageProvider.cs (+15 -1)
📝 src/Jellyfin.Database/Jellyfin.Database.Implementations/Entities/BaseItemImageInfo.cs (+8 -0)
src/Jellyfin.Database/Jellyfin.Database.Implementations/ModelConfiguration/BaseItemImageInfoConfiguration.cs (+22 -0)
src/Jellyfin.Database/Jellyfin.Database.Providers.Sqlite/Migrations/20251022214259_AddSortOrderToBaseItemImageInfo.Designer.cs (+1724 -0)
src/Jellyfin.Database/Jellyfin.Database.Providers.Sqlite/Migrations/20251022214259_AddSortOrderToBaseItemImageInfo.cs (+65 -0)
📝 src/Jellyfin.Database/Jellyfin.Database.Providers.Sqlite/Migrations/JellyfinDbModelSnapshot.cs (+5 -2)

📄 Description

Issue

After migrating from SQLite direct queries to Entity Framework Core, backdrop images are no longer displayed in the correct order. Specifically, fanart.jpg (which should have priority) is often displayed after images from the extrafanart/ folder.

This affects the display when "Select view" is set to "Thumb" or "Thumb Card", the backdrop image shown becomes unpredictable.

Root Cause

In v10.10.7:

  • Images were stored as a serialized string in a single database column
  • Order was preserved during serialization/deserialization

In current main (EF Core):

  • Images are stored in the BaseItemImageInfos table without an explicit order column
  • When loading images, no OrderBy clause was specified
  • EF Core returns images in undefined order (typically database row order)
  • Simple alphabetical sorting doesn't work because extrafanart/fanart1.jpg sorts before fanart.jpg alphabetically

Solution

Implements priority-based sorting that matches the LocalImageProvider discovery order:

  1. {mediaFileName}-fanart.jpg (highest priority)
  2. fanart.jpg (not in extrafanart folder)
  3. fanart-N.jpg (numbered backdrops)
  4. background.jpg / background-N.jpg
  5. art.jpg / art-N.jpg
  6. extrafanart/* folder contents (alphabetical)
  7. backdrop.jpg / backdropN.jpg
  8. Other images (lowest priority)

Within each priority group, images are sorted by numeric index (if present) and then alphabetically by path for stability.

Changes

  • File: Jellyfin.Server.Implementations/Item/BaseItemRepository.cs
  • Added GetImageOrderPriority() helper method to determine priority based on filename patterns
  • Added GetNumericImageIndex() helper method to extract numeric indices from filenames
  • Updated image mapping to apply priority-based ordering

Testing

With a file structure like:

  ├── fanart.jpg
  ├── extrafanart/
  │   ├── fanart1.jpg
  │   ├── fanart2.jpg
  │   └── ...
  └── video.mp4

Before: extrafanart/fanart1.jpg often displayed first
After: fanart.jpg correctly displays first


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/jellyfin/jellyfin/pull/15071 **Author:** [@seeyabye](https://github.com/seeyabye) **Created:** 10/21/2025 **Status:** 🔄 Open **Base:** `release-10.11.z` ← **Head:** `fix-backdrop-image-ordering` --- ### 📝 Commits (10+) - [`c8b8cbf`](https://github.com/jellyfin/jellyfin/commit/c8b8cbf8c412f3bba7edd1b9ee13bea2503cb364) Fix backdrop image ordering regression after EF Core migration by implementing runtime sorting that matches LocalImageProvider discovery order - [`f49e632`](https://github.com/jellyfin/jellyfin/commit/f49e63217193924eafe8c3a1d9f4efbdb673545c) Add database-level SortOrder for backdrop images - [`989cb3c`](https://github.com/jellyfin/jellyfin/commit/989cb3c756db3a4abca5984648912cc516b07428) Improve PopulateImageSortOrder migration with async and memory efficiency - [`2b4942d`](https://github.com/jellyfin/jellyfin/commit/2b4942d470ba2214f64a8d764990677f592bb8d9) Changed composite index to include ImageType - [`65160f2`](https://github.com/jellyfin/jellyfin/commit/65160f2c8bf803a9ed10b125381662b938485307) Prepoluate SortOrder before correction - [`ca5443e`](https://github.com/jellyfin/jellyfin/commit/ca5443ee13f82323093aa9b1963621b888509bc7) Changed SaveImage logic - [`ddb641e`](https://github.com/jellyfin/jellyfin/commit/ddb641e479af745c067fca6f9a180cbcd89f02bb) Fixed SortOrder not being populated on new scans - [`6385474`](https://github.com/jellyfin/jellyfin/commit/638547417fff1793c967154dc9dfc9937316c49a) Cleanup - [`e90321a`](https://github.com/jellyfin/jellyfin/commit/e90321a9e3055d15039cb1752ec613b6463e741d) Fixed SortOrder for Web Uploads - [`1ec2815`](https://github.com/jellyfin/jellyfin/commit/1ec281554baab469856e3375b47ce3524bf6de9b) Fixed AddImage's ordering to ensure consistency ### 📊 Changes **12 files changed** (+2380 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `Jellyfin.Server.Implementations/Item/BaseItemRepository.cs` (+123 -8) ➕ `Jellyfin.Server/Migrations/Routines/PopulateImageSortOrder.cs` (+253 -0) 📝 `MediaBrowser.Controller/Entities/BaseItem.cs` (+95 -19) 📝 `MediaBrowser.Controller/Entities/ItemImageInfo.cs` (+7 -0) 📝 `MediaBrowser.Controller/Persistence/IItemRepository.cs` (+10 -0) ➕ `MediaBrowser.Controller/Utilities/ImageOrderingUtilities.cs` (+53 -0) 📝 `MediaBrowser.LocalMetadata/Images/LocalImageProvider.cs` (+15 -1) 📝 `src/Jellyfin.Database/Jellyfin.Database.Implementations/Entities/BaseItemImageInfo.cs` (+8 -0) ➕ `src/Jellyfin.Database/Jellyfin.Database.Implementations/ModelConfiguration/BaseItemImageInfoConfiguration.cs` (+22 -0) ➕ `src/Jellyfin.Database/Jellyfin.Database.Providers.Sqlite/Migrations/20251022214259_AddSortOrderToBaseItemImageInfo.Designer.cs` (+1724 -0) ➕ `src/Jellyfin.Database/Jellyfin.Database.Providers.Sqlite/Migrations/20251022214259_AddSortOrderToBaseItemImageInfo.cs` (+65 -0) 📝 `src/Jellyfin.Database/Jellyfin.Database.Providers.Sqlite/Migrations/JellyfinDbModelSnapshot.cs` (+5 -2) </details> ### 📄 Description ## Issue After migrating from SQLite direct queries to Entity Framework Core, backdrop images are no longer displayed in the correct order. Specifically, `fanart.jpg` (which should have priority) is often displayed after images from the `extrafanart/` folder. This affects the display when "Select view" is set to "Thumb" or "Thumb Card", the backdrop image shown becomes unpredictable. ### Root Cause **In v10.10.7:** - Images were stored as a serialized string in a single database column - Order was preserved during serialization/deserialization **In current main (EF Core):** - Images are stored in the `BaseItemImageInfos` table without an explicit order column - When loading images, no `OrderBy` clause was specified - EF Core returns images in undefined order (typically database row order) - Simple alphabetical sorting doesn't work because `extrafanart/fanart1.jpg` sorts before `fanart.jpg` alphabetically ### Solution Implements priority-based sorting that matches the `LocalImageProvider` discovery order: 1. `{mediaFileName}-fanart.jpg` (highest priority) 2. `fanart.jpg` (not in extrafanart folder) 3. `fanart-N.jpg` (numbered backdrops) 4. `background.jpg` / `background-N.jpg` 5. `art.jpg` / `art-N.jpg` 6. `extrafanart/*` folder contents (alphabetical) 7. `backdrop.jpg` / `backdropN.jpg` 8. Other images (lowest priority) Within each priority group, images are sorted by numeric index (if present) and then alphabetically by path for stability. ### Changes - **File**: `Jellyfin.Server.Implementations/Item/BaseItemRepository.cs` - Added `GetImageOrderPriority()` helper method to determine priority based on filename patterns - Added `GetNumericImageIndex()` helper method to extract numeric indices from filenames - Updated image mapping to apply priority-based ordering ### Testing With a file structure like: ``` ├── fanart.jpg ├── extrafanart/ │ ├── fanart1.jpg │ ├── fanart2.jpg │ └── ... └── video.mp4 ``` **Before**: `extrafanart/fanart1.jpg` often displayed first **After**: `fanart.jpg` correctly displays first --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
backuprepo added the
pull-request
label 2025-12-22 10:17:01 +01:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: starred/jellyfin#14050
No description provided.