mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
More
This commit is contained in:
parent
27c29bbb4c
commit
b6954f3bfd
@ -15,14 +15,14 @@ namespace Emby.Server.Implementations.Activity
|
|||||||
{
|
{
|
||||||
public class ActivityRepository : BaseSqliteRepository, IActivityRepository
|
public class ActivityRepository : BaseSqliteRepository, IActivityRepository
|
||||||
{
|
{
|
||||||
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
private static readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||||
protected IFileSystem FileSystem { get; private set; }
|
private readonly IFileSystem _fileSystem;
|
||||||
|
|
||||||
public ActivityRepository(ILoggerFactory loggerFactory, IServerApplicationPaths appPaths, IFileSystem fileSystem)
|
public ActivityRepository(ILoggerFactory loggerFactory, IServerApplicationPaths appPaths, IFileSystem fileSystem)
|
||||||
: base(loggerFactory.CreateLogger(nameof(ActivityRepository)))
|
: base(loggerFactory.CreateLogger(nameof(ActivityRepository)))
|
||||||
{
|
{
|
||||||
DbFilePath = Path.Combine(appPaths.DataPath, "activitylog.db");
|
DbFilePath = Path.Combine(appPaths.DataPath, "activitylog.db");
|
||||||
FileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
@ -35,7 +35,7 @@ namespace Emby.Server.Implementations.Activity
|
|||||||
{
|
{
|
||||||
Logger.LogError(ex, "Error loading database file. Will reset and retry.");
|
Logger.LogError(ex, "Error loading database file. Will reset and retry.");
|
||||||
|
|
||||||
FileSystem.DeleteFile(DbFilePath);
|
_fileSystem.DeleteFile(DbFilePath);
|
||||||
|
|
||||||
InitializeInternal();
|
InitializeInternal();
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ namespace Emby.Server.Implementations.Data
|
|||||||
{
|
{
|
||||||
protected string DbFilePath { get; set; }
|
protected string DbFilePath { get; set; }
|
||||||
|
|
||||||
protected ILogger Logger { get; private set; }
|
protected ILogger Logger { get; }
|
||||||
|
|
||||||
protected BaseSqliteRepository(ILogger logger)
|
protected BaseSqliteRepository(ILogger logger)
|
||||||
{
|
{
|
||||||
@ -23,31 +23,23 @@ namespace Emby.Server.Implementations.Data
|
|||||||
|
|
||||||
protected TransactionMode ReadTransactionMode => TransactionMode.Deferred;
|
protected TransactionMode ReadTransactionMode => TransactionMode.Deferred;
|
||||||
|
|
||||||
internal static int ThreadSafeMode { get; set; }
|
|
||||||
|
|
||||||
protected virtual ConnectionFlags DefaultConnectionFlags => ConnectionFlags.SharedCached | ConnectionFlags.NoMutex;
|
protected virtual ConnectionFlags DefaultConnectionFlags => ConnectionFlags.SharedCached | ConnectionFlags.NoMutex;
|
||||||
|
|
||||||
private readonly SemaphoreSlim WriteLock = new SemaphoreSlim(1, 1);
|
private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1, 1);
|
||||||
|
|
||||||
private SQLiteDatabaseConnection WriteConnection;
|
private SQLiteDatabaseConnection _writeConnection;
|
||||||
|
|
||||||
static BaseSqliteRepository()
|
|
||||||
{
|
|
||||||
ThreadSafeMode = raw.sqlite3_threadsafe();
|
|
||||||
raw.sqlite3_enable_shared_cache(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private string _defaultWal;
|
private string _defaultWal;
|
||||||
|
|
||||||
protected ManagedConnection GetConnection(bool isReadOnly = false)
|
protected ManagedConnection GetConnection(bool _ = false)
|
||||||
{
|
{
|
||||||
WriteLock.Wait();
|
_writeLock.Wait();
|
||||||
if (WriteConnection != null)
|
if (_writeConnection != null)
|
||||||
{
|
{
|
||||||
return new ManagedConnection(WriteConnection, WriteLock);
|
return new ManagedConnection(_writeConnection, _writeLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteConnection = SQLite3.Open(
|
_writeConnection = SQLite3.Open(
|
||||||
DbFilePath,
|
DbFilePath,
|
||||||
DefaultConnectionFlags | ConnectionFlags.Create | ConnectionFlags.ReadWrite,
|
DefaultConnectionFlags | ConnectionFlags.Create | ConnectionFlags.ReadWrite,
|
||||||
null);
|
null);
|
||||||
@ -55,21 +47,21 @@ namespace Emby.Server.Implementations.Data
|
|||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(_defaultWal))
|
if (string.IsNullOrWhiteSpace(_defaultWal))
|
||||||
{
|
{
|
||||||
_defaultWal = WriteConnection.Query("PRAGMA journal_mode").SelectScalarString().First();
|
_defaultWal = _writeConnection.Query("PRAGMA journal_mode").SelectScalarString().First();
|
||||||
|
|
||||||
Logger.LogInformation("Default journal_mode for {0} is {1}", DbFilePath, _defaultWal);
|
Logger.LogInformation("Default journal_mode for {0} is {1}", DbFilePath, _defaultWal);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EnableTempStoreMemory)
|
if (EnableTempStoreMemory)
|
||||||
{
|
{
|
||||||
WriteConnection.Execute("PRAGMA temp_store = memory");
|
_writeConnection.Execute("PRAGMA temp_store = memory");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WriteConnection.Execute("PRAGMA temp_store = file");
|
_writeConnection.Execute("PRAGMA temp_store = file");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ManagedConnection(WriteConnection, WriteLock);
|
return new ManagedConnection(_writeConnection, _writeLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IStatement PrepareStatement(ManagedConnection connection, string sql)
|
public IStatement PrepareStatement(ManagedConnection connection, string sql)
|
||||||
@ -170,20 +162,20 @@ namespace Emby.Server.Implementations.Data
|
|||||||
|
|
||||||
if (dispose)
|
if (dispose)
|
||||||
{
|
{
|
||||||
WriteLock.Wait();
|
_writeLock.Wait();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
WriteConnection.Dispose();
|
_writeConnection.Dispose();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
WriteLock.Release();
|
_writeLock.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteLock.Dispose();
|
_writeLock.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteConnection = null;
|
_writeConnection = null;
|
||||||
|
|
||||||
_disposed = true;
|
_disposed = true;
|
||||||
}
|
}
|
||||||
|
@ -18,13 +18,13 @@ namespace Emby.Server.Implementations.Data
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SqliteDisplayPreferencesRepository : BaseSqliteRepository, IDisplayPreferencesRepository
|
public class SqliteDisplayPreferencesRepository : BaseSqliteRepository, IDisplayPreferencesRepository
|
||||||
{
|
{
|
||||||
protected IFileSystem FileSystem { get; private set; }
|
private readonly IFileSystem _fileSystem;
|
||||||
|
|
||||||
public SqliteDisplayPreferencesRepository(ILoggerFactory loggerFactory, IJsonSerializer jsonSerializer, IApplicationPaths appPaths, IFileSystem fileSystem)
|
public SqliteDisplayPreferencesRepository(ILoggerFactory loggerFactory, IJsonSerializer jsonSerializer, IApplicationPaths appPaths, IFileSystem fileSystem)
|
||||||
: base(loggerFactory.CreateLogger(nameof(SqliteDisplayPreferencesRepository)))
|
: base(loggerFactory.CreateLogger(nameof(SqliteDisplayPreferencesRepository)))
|
||||||
{
|
{
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
FileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
DbFilePath = Path.Combine(appPaths.DataPath, "displaypreferences.db");
|
DbFilePath = Path.Combine(appPaths.DataPath, "displaypreferences.db");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ namespace Emby.Server.Implementations.Data
|
|||||||
{
|
{
|
||||||
Logger.LogError(ex, "Error loading database file. Will reset and retry.");
|
Logger.LogError(ex, "Error loading database file. Will reset and retry.");
|
||||||
|
|
||||||
FileSystem.DeleteFile(DbFilePath);
|
_fileSystem.DeleteFile(DbFilePath);
|
||||||
|
|
||||||
InitializeInternal();
|
InitializeInternal();
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using Serilog.AspNetCore;
|
using Serilog.AspNetCore;
|
||||||
|
using SQLitePCL;
|
||||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||||
|
|
||||||
namespace Jellyfin.Server
|
namespace Jellyfin.Server
|
||||||
@ -126,7 +127,11 @@ namespace Jellyfin.Server
|
|||||||
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
|
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
|
||||||
#pragma warning restore CA5359
|
#pragma warning restore CA5359
|
||||||
|
|
||||||
SQLitePCL.Batteries_V2.Init();
|
Batteries_V2.Init();
|
||||||
|
if (raw.sqlite3_enable_shared_cache(1) != raw.SQLITE_OK)
|
||||||
|
{
|
||||||
|
Console.WriteLine("WARN: Failed to enable shared cache for SQLite");
|
||||||
|
}
|
||||||
|
|
||||||
using (var appHost = new CoreAppHost(
|
using (var appHost = new CoreAppHost(
|
||||||
appPaths,
|
appPaths,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user