[PR #6031] [MERGED] Run SQLite query planner optimization at shutdown/restart #10786

Closed
opened 2026-02-07 06:26:39 +03:00 by OVERLORD · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/jellyfin/jellyfin/pull/6031
Author: @ferferga
Created: 5/12/2021
Status: Merged
Merged: 5/24/2021
Merged by: @cvium

Base: masterHead: sql-optimization


📝 Commits (3)

  • 69baa9c Run SQLite query planner optimization at shutdown/restart
  • 3b82211 Create scheduled task for database optimization
  • 6db229a Address review comments

📊 Changes

5 files changed (+118 additions, -2 deletions)

View changed files

📝 Emby.Server.Implementations/Emby.Server.Implementations.csproj (+1 -0)
📝 Emby.Server.Implementations/Localization/Core/en-US.json (+3 -1)
📝 Emby.Server.Implementations/Localization/Core/es.json (+3 -1)
Emby.Server.Implementations/ScheduledTasks/Tasks/OptimizeDatabaseTask.cs (+101 -0)
📝 Jellyfin.Server/Program.cs (+10 -0)

📄 Description

Runs PRAGMA optimize after disposing Jellyfin's application host. According to SQLite docs, this should be run at the end of the connection, when it's most suitable to run the query planner optimizations.

Source https://www.sqlite.org/pragma.html#pragma_optimize and https://sqlite.org/lang_analyze.html

EFCore arbitrarily creates or reuses connections for database contexts (based in EF6, not EFCore documentation I could find, https://docs.microsoft.com/en-us/ef/ef6/fundamentals/connection-management) but I assume that with SQLite provider (given all the concurrency issues it has) the same connection is reused no matter what, so we're taking full advantage of the query planner. More insights on this are appreciated.


🔄 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/6031 **Author:** [@ferferga](https://github.com/ferferga) **Created:** 5/12/2021 **Status:** ✅ Merged **Merged:** 5/24/2021 **Merged by:** [@cvium](https://github.com/cvium) **Base:** `master` ← **Head:** `sql-optimization` --- ### 📝 Commits (3) - [`69baa9c`](https://github.com/jellyfin/jellyfin/commit/69baa9c4679d376f001cc71ec0a0d9a1791e7adf) Run SQLite query planner optimization at shutdown/restart - [`3b82211`](https://github.com/jellyfin/jellyfin/commit/3b822116ed8b89da82d5b90cd0fdca070def6377) Create scheduled task for database optimization - [`6db229a`](https://github.com/jellyfin/jellyfin/commit/6db229af5deb6a00035ddcfebc4fd9db3b6a5336) Address review comments ### 📊 Changes **5 files changed** (+118 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `Emby.Server.Implementations/Emby.Server.Implementations.csproj` (+1 -0) 📝 `Emby.Server.Implementations/Localization/Core/en-US.json` (+3 -1) 📝 `Emby.Server.Implementations/Localization/Core/es.json` (+3 -1) ➕ `Emby.Server.Implementations/ScheduledTasks/Tasks/OptimizeDatabaseTask.cs` (+101 -0) 📝 `Jellyfin.Server/Program.cs` (+10 -0) </details> ### 📄 Description Runs ``PRAGMA optimize`` after disposing Jellyfin's application host. According to SQLite docs, this should be run at the end of the connection, when it's most suitable to run the query planner optimizations. Source https://www.sqlite.org/pragma.html#pragma_optimize and https://sqlite.org/lang_analyze.html EFCore arbitrarily creates or reuses connections for database contexts (based in EF6, not EFCore documentation I could find, https://docs.microsoft.com/en-us/ef/ef6/fundamentals/connection-management) but I assume that with SQLite provider (given all the concurrency issues it has) the same connection is reused no matter what, so we're taking full advantage of the query planner. **More insights on this are appreciated**. --- <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 06:26:39 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/jellyfin#10786