aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/Migrations/Routines/AddPeopleQueryIndex.cs
diff options
context:
space:
mode:
authorWWWesten <4700006+WWWesten@users.noreply.github.com>2021-11-01 23:43:29 +0500
committerGitHub <noreply@github.com>2021-11-01 23:43:29 +0500
commit0a14279e2a21bcb9654a06a2d49e1e4f0cc5329c (patch)
treee1b1bd603b011ca98e5793e356326bf4a35a7050 /Jellyfin.Server/Migrations/Routines/AddPeopleQueryIndex.cs
parentf2817fef743eeb75a00782ceea363b2d3e7dc9f2 (diff)
parent76eeb8f655424d295e73ced8349c6fefee6ddb12 (diff)
Merge branch 'jellyfin:master' into master
Diffstat (limited to 'Jellyfin.Server/Migrations/Routines/AddPeopleQueryIndex.cs')
-rw-r--r--Jellyfin.Server/Migrations/Routines/AddPeopleQueryIndex.cs49
1 files changed, 49 insertions, 0 deletions
diff --git a/Jellyfin.Server/Migrations/Routines/AddPeopleQueryIndex.cs b/Jellyfin.Server/Migrations/Routines/AddPeopleQueryIndex.cs
new file mode 100644
index 000000000..6343c422d
--- /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 IF NOT EXISTS idx_TypedBaseItemsUserDataKeyType ON TypedBaseItems(UserDataKey, Type);");
+ _logger.LogInformation("Creating index idx_PeopleNameListOrder");
+ connection.Execute("CREATE INDEX IF NOT EXISTS idx_PeopleNameListOrder ON People(Name, ListOrder);");
+ }
+ }
+}