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

Open
opened 2026-02-07 07:26:32 +03:00 by OVERLORD · 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+)

  • 0ddc948 Fix backdrop image ordering regression after EF Core migration by implementing runtime sorting that matches LocalImageProvider discovery order
  • 7c0b011 Add database-level SortOrder for backdrop images
  • 8f0e090 Improve PopulateImageSortOrder migration with async and memory efficiency
  • bbf56da Changed composite index to include ImageType
  • 5b653e5 Prepoluate SortOrder before correction
  • 8ac3d08 Changed SaveImage logic
  • 5b6c9eb Fixed SortOrder not being populated on new scans
  • 888170b Cleanup
  • aac467f Fixed SortOrder for Web Uploads
  • 8d7237b 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+) - [`0ddc948`](https://github.com/jellyfin/jellyfin/commit/0ddc9483ba3852fa36e522a4c22c2b0ba7187671) Fix backdrop image ordering regression after EF Core migration by implementing runtime sorting that matches LocalImageProvider discovery order - [`7c0b011`](https://github.com/jellyfin/jellyfin/commit/7c0b011a48844fe762e84f4e4902dc97d373f72e) Add database-level SortOrder for backdrop images - [`8f0e090`](https://github.com/jellyfin/jellyfin/commit/8f0e090e53df47c771e05fa7e16a54728f2b03a8) Improve PopulateImageSortOrder migration with async and memory efficiency - [`bbf56da`](https://github.com/jellyfin/jellyfin/commit/bbf56da0910b90ca03ea5a3e72b4b2f6b9bbb1e7) Changed composite index to include ImageType - [`5b653e5`](https://github.com/jellyfin/jellyfin/commit/5b653e5f87834953b608b7001d76d2a515c6f9ae) Prepoluate SortOrder before correction - [`8ac3d08`](https://github.com/jellyfin/jellyfin/commit/8ac3d08e7691d504d4cfff70e1e8a7fac6725bf4) Changed SaveImage logic - [`5b6c9eb`](https://github.com/jellyfin/jellyfin/commit/5b6c9eb18f8d40014cf8a334a70df7f27c4c12bd) Fixed SortOrder not being populated on new scans - [`888170b`](https://github.com/jellyfin/jellyfin/commit/888170b1fc52c3d31a5a5159a3d10fdede8cbd42) Cleanup - [`aac467f`](https://github.com/jellyfin/jellyfin/commit/aac467f9a17037fbae6dc5a0426c803b9a7702e5) Fixed SortOrder for Web Uploads - [`8d7237b`](https://github.com/jellyfin/jellyfin/commit/8d7237bcef3d7e1287ded19006dc459bc12e7377) 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>
OVERLORD added the pull-request label 2026-02-07 07:26:32 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/jellyfin#14230