Merge pull request #9044 from Bond-009/db
This commit is contained in:
commit
be206d4ff2
|
@ -60,11 +60,22 @@ namespace Emby.Server.Implementations.Data
|
|||
/// <value>The cache size or null.</value>
|
||||
protected virtual int? CacheSize => null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the locking mode. <see href="https://www.sqlite.org/pragma.html#pragma_locking_mode" />.
|
||||
/// </summary>
|
||||
protected virtual string LockingMode => "EXCLUSIVE";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the journal mode. <see href="https://www.sqlite.org/pragma.html#pragma_journal_mode" />.
|
||||
/// </summary>
|
||||
/// <value>The journal mode.</value>
|
||||
protected virtual string JournalMode => "TRUNCATE";
|
||||
protected virtual string JournalMode => "WAL";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the journal size limit. <see href="https://www.sqlite.org/pragma.html#pragma_journal_size_limit" />.
|
||||
/// </summary>
|
||||
/// <value>The journal size limit.</value>
|
||||
protected virtual int? JournalSizeLimit => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the page size.
|
||||
|
@ -84,7 +95,7 @@ namespace Emby.Server.Implementations.Data
|
|||
/// </summary>
|
||||
/// <value>The synchronous mode or null.</value>
|
||||
/// <see cref="SynchronousMode"/>
|
||||
protected virtual SynchronousMode? Synchronous => null;
|
||||
protected virtual SynchronousMode? Synchronous => SynchronousMode.Normal;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the write lock.
|
||||
|
@ -116,11 +127,21 @@ namespace Emby.Server.Implementations.Data
|
|||
WriteConnection.Execute("PRAGMA cache_size=" + CacheSize.Value);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(LockingMode))
|
||||
{
|
||||
WriteConnection.Execute("PRAGMA locking_mode=" + LockingMode);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(JournalMode))
|
||||
{
|
||||
WriteConnection.Execute("PRAGMA journal_mode=" + JournalMode);
|
||||
}
|
||||
|
||||
if (JournalSizeLimit.HasValue)
|
||||
{
|
||||
WriteConnection.Execute("PRAGMA journal_size_limit=" + (int)JournalSizeLimit.Value);
|
||||
}
|
||||
|
||||
if (Synchronous.HasValue)
|
||||
{
|
||||
WriteConnection.Execute("PRAGMA synchronous=" + (int)Synchronous.Value);
|
||||
|
|
|
@ -359,8 +359,6 @@ namespace Emby.Server.Implementations.Data
|
|||
|
||||
string[] queries =
|
||||
{
|
||||
"PRAGMA locking_mode=EXCLUSIVE",
|
||||
|
||||
"create table if not exists TypedBaseItems (guid GUID primary key NOT NULL, type TEXT NOT NULL, data BLOB NULL, ParentId GUID NULL, Path TEXT NULL)",
|
||||
|
||||
"create table if not exists AncestorIds (ItemId GUID NOT NULL, AncestorId GUID NOT NULL, AncestorIdText TEXT NOT NULL, PRIMARY KEY (ItemId, AncestorId))",
|
||||
|
@ -385,39 +383,6 @@ namespace Emby.Server.Implementations.Data
|
|||
|
||||
string[] postQueries =
|
||||
{
|
||||
// obsolete
|
||||
"drop index if exists idx_TypedBaseItems",
|
||||
"drop index if exists idx_mediastreams",
|
||||
"drop index if exists idx_mediastreams1",
|
||||
"drop index if exists idx_" + ChaptersTableName,
|
||||
"drop index if exists idx_UserDataKeys1",
|
||||
"drop index if exists idx_UserDataKeys2",
|
||||
"drop index if exists idx_TypeTopParentId3",
|
||||
"drop index if exists idx_TypeTopParentId2",
|
||||
"drop index if exists idx_TypeTopParentId4",
|
||||
"drop index if exists idx_Type",
|
||||
"drop index if exists idx_TypeTopParentId",
|
||||
"drop index if exists idx_GuidType",
|
||||
"drop index if exists idx_TopParentId",
|
||||
"drop index if exists idx_TypeTopParentId6",
|
||||
"drop index if exists idx_ItemValues2",
|
||||
"drop index if exists Idx_ProviderIds",
|
||||
"drop index if exists idx_ItemValues3",
|
||||
"drop index if exists idx_ItemValues4",
|
||||
"drop index if exists idx_ItemValues5",
|
||||
"drop index if exists idx_UserDataKeys3",
|
||||
"drop table if exists UserDataKeys",
|
||||
"drop table if exists ProviderIds",
|
||||
"drop index if exists Idx_ProviderIds1",
|
||||
"drop table if exists Images",
|
||||
"drop index if exists idx_Images",
|
||||
"drop index if exists idx_TypeSeriesPresentationUniqueKey",
|
||||
"drop index if exists idx_SeriesPresentationUniqueKey",
|
||||
"drop index if exists idx_TypeSeriesPresentationUniqueKey2",
|
||||
"drop index if exists idx_AncestorIds3",
|
||||
"drop index if exists idx_AncestorIds4",
|
||||
"drop index if exists idx_AncestorIds2",
|
||||
|
||||
"create index if not exists idx_PathTypedBaseItems on TypedBaseItems(Path)",
|
||||
"create index if not exists idx_ParentIdTypedBaseItems on TypedBaseItems(ParentId)",
|
||||
|
||||
|
@ -458,6 +423,9 @@ namespace Emby.Server.Implementations.Data
|
|||
|
||||
// Used to update inherited tags
|
||||
"create index if not exists idx_ItemValues8 on ItemValues(Type, ItemId, Value)",
|
||||
|
||||
"CREATE INDEX IF NOT EXISTS idx_TypedBaseItemsUserDataKeyType ON TypedBaseItems(UserDataKey, Type)",
|
||||
"CREATE INDEX IF NOT EXISTS idx_PeopleNameListOrder ON People(Name, ListOrder)"
|
||||
};
|
||||
|
||||
using (var connection = GetConnection())
|
||||
|
|
|
@ -38,7 +38,6 @@ namespace Jellyfin.Server.Migrations
|
|||
typeof(Routines.ReaddDefaultPluginRepository),
|
||||
typeof(Routines.MigrateDisplayPreferencesDb),
|
||||
typeof(Routines.RemoveDownloadImagesInAdvance),
|
||||
typeof(Routines.AddPeopleQueryIndex),
|
||||
typeof(Routines.MigrateAuthenticationDb)
|
||||
};
|
||||
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
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);");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -273,10 +273,6 @@ namespace Jellyfin.Server
|
|||
ServicePointManager.Expect100Continue = false;
|
||||
|
||||
Batteries_V2.Init();
|
||||
if (raw.sqlite3_enable_shared_cache(1) != raw.SQLITE_OK)
|
||||
{
|
||||
_logger.LogWarning("Failed to enable shared cache for SQLite");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue
Block a user