2
0

AddPeopleQueryIndex.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.IO;
  3. using MediaBrowser.Controller;
  4. using Microsoft.Extensions.Logging;
  5. using SQLitePCL.pretty;
  6. namespace Jellyfin.Server.Migrations.Routines
  7. {
  8. /// <summary>
  9. /// Migration to add table indexes to optimize the Persons query.
  10. /// </summary>
  11. public class AddPeopleQueryIndex : IMigrationRoutine
  12. {
  13. private const string DbFilename = "library.db";
  14. private readonly ILogger<AddPeopleQueryIndex> _logger;
  15. private readonly IServerApplicationPaths _serverApplicationPaths;
  16. /// <summary>
  17. /// Initializes a new instance of the <see cref="AddPeopleQueryIndex"/> class.
  18. /// </summary>
  19. /// <param name="logger">Instance of the <see cref="ILogger{AddPeopleQueryIndex}"/> interface.</param>
  20. /// <param name="serverApplicationPaths">Instance of the <see cref="IServerApplicationPaths"/> interface.</param>
  21. public AddPeopleQueryIndex(ILogger<AddPeopleQueryIndex> logger, IServerApplicationPaths serverApplicationPaths)
  22. {
  23. _logger = logger;
  24. _serverApplicationPaths = serverApplicationPaths;
  25. }
  26. /// <inheritdoc />
  27. public Guid Id => new Guid("DE009B59-BAAE-428D-A810-F67762DC05B8");
  28. /// <inheritdoc />
  29. public string Name => "AddPeopleQueryIndex";
  30. /// <inheritdoc />
  31. public bool PerformOnNewInstall => true;
  32. /// <inheritdoc />
  33. public void Perform()
  34. {
  35. var databasePath = Path.Join(_serverApplicationPaths.DataPath, DbFilename);
  36. using var connection = SQLite3.Open(databasePath, ConnectionFlags.ReadWrite, null);
  37. _logger.LogInformation("Creating index idx_TypedBaseItemsUserDataKeyType");
  38. connection.Execute("CREATE INDEX IF NOT EXISTS idx_TypedBaseItemsUserDataKeyType ON TypedBaseItems(UserDataKey, Type);");
  39. _logger.LogInformation("Creating index idx_PeopleNameListOrder");
  40. connection.Execute("CREATE INDEX IF NOT EXISTS idx_PeopleNameListOrder ON People(Name, ListOrder);");
  41. }
  42. }
  43. }