aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server
diff options
context:
space:
mode:
authorJoshua M. Boniface <joshua@boniface.me>2020-12-04 20:05:35 -0500
committerGitHub <noreply@github.com>2020-12-04 20:05:35 -0500
commitb96d4ef0e8ffa8429c25c83739a9c392a12e9d82 (patch)
tree9d58df71a2f9db7bdb11f0fe52239888c97a1f35 /Jellyfin.Server
parent4e6584c345a45c3ac46ac3aa95d39472eb6fbcbf (diff)
parent60b7e49a7f62e5f1ab06e3c85665f900235f2ff5 (diff)
Merge pull request #4653 from crobibero/favorite-persons
Optimize FavoritePersons query
Diffstat (limited to 'Jellyfin.Server')
-rw-r--r--Jellyfin.Server/Migrations/MigrationRunner.cs3
-rw-r--r--Jellyfin.Server/Migrations/Routines/AddPeopleQueryIndex.cs49
2 files changed, 51 insertions, 1 deletions
diff --git a/Jellyfin.Server/Migrations/MigrationRunner.cs b/Jellyfin.Server/Migrations/MigrationRunner.cs
index aca165408..305660ae6 100644
--- a/Jellyfin.Server/Migrations/MigrationRunner.cs
+++ b/Jellyfin.Server/Migrations/MigrationRunner.cs
@@ -24,7 +24,8 @@ namespace Jellyfin.Server.Migrations
typeof(Routines.MigrateUserDb),
typeof(Routines.ReaddDefaultPluginRepository),
typeof(Routines.MigrateDisplayPreferencesDb),
- typeof(Routines.RemoveDownloadImagesInAdvance)
+ typeof(Routines.RemoveDownloadImagesInAdvance),
+ typeof(Routines.AddPeopleQueryIndex)
};
/// <summary>
diff --git a/Jellyfin.Server/Migrations/Routines/AddPeopleQueryIndex.cs b/Jellyfin.Server/Migrations/Routines/AddPeopleQueryIndex.cs
new file mode 100644
index 000000000..2521d9952
--- /dev/null
+++ b/Jellyfin.Server/Migrations/Routines/AddPeopleQueryIndex.cs
@@ -0,0 +1,49 @@
+using System;
+using System.IO;
+using MediaBrowser.Controller;
+using Microsoft.Extensions.Logging;
+using SQLitePCL.pretty;
+
+namespace Jellyfin.Server.Migrations.Routines
+{
+ /// <summary>
+ /// Migration to add table indexes to optimize the Persons query.
+ /// </summary>
+ public class AddPeopleQueryIndex : IMigrationRoutine
+ {
+ private const string DbFilename = "library.db";
+ private readonly ILogger<AddPeopleQueryIndex> _logger;
+ private readonly IServerApplicationPaths _serverApplicationPaths;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="AddPeopleQueryIndex"/> class.
+ /// </summary>
+ /// <param name="logger">Instance of the <see cref="ILogger{AddPeopleQueryIndex}"/> interface.</param>
+ /// <param name="serverApplicationPaths">Instance of the <see cref="IServerApplicationPaths"/> interface.</param>
+ public AddPeopleQueryIndex(ILogger<AddPeopleQueryIndex> logger, IServerApplicationPaths serverApplicationPaths)
+ {
+ _logger = logger;
+ _serverApplicationPaths = serverApplicationPaths;
+ }
+
+ /// <inheritdoc />
+ public Guid Id => new Guid("DE009B59-BAAE-428D-A810-F67762DC05B8");
+
+ /// <inheritdoc />
+ public string Name => "AddPeopleQueryIndex";
+
+ /// <inheritdoc />
+ public bool PerformOnNewInstall => true;
+
+ /// <inheritdoc />
+ public void Perform()
+ {
+ var databasePath = Path.Join(_serverApplicationPaths.DataPath, DbFilename);
+ using var connection = SQLite3.Open(databasePath, ConnectionFlags.ReadWrite, null);
+ _logger.LogInformation("Creating index idx_TypedBaseItemsUserDataKeyType");
+ connection.Execute("CREATE INDEX idx_TypedBaseItemsUserDataKeyType ON TypedBaseItems(UserDataKey, Type);");
+ _logger.LogInformation("Creating index idx_PeopleNameListOrder");
+ connection.Execute("CREATE INDEX idx_PeopleNameListOrder ON People(Name, ListOrder);");
+ }
+ }
+} \ No newline at end of file