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
|
||||
{
|
||||
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||
protected IFileSystem FileSystem { get; private set; }
|
||||
private static readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||
private readonly IFileSystem _fileSystem;
|
||||
|
||||
public ActivityRepository(ILoggerFactory loggerFactory, IServerApplicationPaths appPaths, IFileSystem fileSystem)
|
||||
: base(loggerFactory.CreateLogger(nameof(ActivityRepository)))
|
||||
{
|
||||
DbFilePath = Path.Combine(appPaths.DataPath, "activitylog.db");
|
||||
FileSystem = fileSystem;
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
@ -35,7 +35,7 @@ namespace Emby.Server.Implementations.Activity
|
||||
{
|
||||
Logger.LogError(ex, "Error loading database file. Will reset and retry.");
|
||||
|
||||
FileSystem.DeleteFile(DbFilePath);
|
||||
_fileSystem.DeleteFile(DbFilePath);
|
||||
|
||||
InitializeInternal();
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace Emby.Server.Implementations.Data
|
||||
{
|
||||
protected string DbFilePath { get; set; }
|
||||
|
||||
protected ILogger Logger { get; private set; }
|
||||
protected ILogger Logger { get; }
|
||||
|
||||
protected BaseSqliteRepository(ILogger logger)
|
||||
{
|
||||
@ -23,31 +23,23 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
protected TransactionMode ReadTransactionMode => TransactionMode.Deferred;
|
||||
|
||||
internal static int ThreadSafeMode { get; set; }
|
||||
|
||||
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;
|
||||
|
||||
static BaseSqliteRepository()
|
||||
{
|
||||
ThreadSafeMode = raw.sqlite3_threadsafe();
|
||||
raw.sqlite3_enable_shared_cache(1);
|
||||
}
|
||||
private SQLiteDatabaseConnection _writeConnection;
|
||||
|
||||
private string _defaultWal;
|
||||
|
||||
protected ManagedConnection GetConnection(bool isReadOnly = false)
|
||||
protected ManagedConnection GetConnection(bool _ = false)
|
||||
{
|
||||
WriteLock.Wait();
|
||||
if (WriteConnection != null)
|
||||
_writeLock.Wait();
|
||||
if (_writeConnection != null)
|
||||
{
|
||||
return new ManagedConnection(WriteConnection, WriteLock);
|
||||
return new ManagedConnection(_writeConnection, _writeLock);
|
||||
}
|
||||
|
||||
WriteConnection = SQLite3.Open(
|
||||
_writeConnection = SQLite3.Open(
|
||||
DbFilePath,
|
||||
DefaultConnectionFlags | ConnectionFlags.Create | ConnectionFlags.ReadWrite,
|
||||
null);
|
||||
@ -55,21 +47,21 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (EnableTempStoreMemory)
|
||||
{
|
||||
WriteConnection.Execute("PRAGMA temp_store = memory");
|
||||
_writeConnection.Execute("PRAGMA temp_store = memory");
|
||||
}
|
||||
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)
|
||||
@ -170,20 +162,20 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
if (dispose)
|
||||
{
|
||||
WriteLock.Wait();
|
||||
_writeLock.Wait();
|
||||
try
|
||||
{
|
||||
WriteConnection.Dispose();
|
||||
_writeConnection.Dispose();
|
||||
}
|
||||
finally
|
||||
{
|
||||
WriteLock.Release();
|
||||
_writeLock.Release();
|
||||
}
|
||||
|
||||
WriteLock.Dispose();
|
||||
_writeLock.Dispose();
|
||||
}
|
||||
|
||||
WriteConnection = null;
|
||||
_writeConnection = null;
|
||||
|
||||
_disposed = true;
|
||||
}
|
||||
|
@ -18,13 +18,13 @@ namespace Emby.Server.Implementations.Data
|
||||
/// </summary>
|
||||
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)
|
||||
: base(loggerFactory.CreateLogger(nameof(SqliteDisplayPreferencesRepository)))
|
||||
{
|
||||
_jsonSerializer = jsonSerializer;
|
||||
FileSystem = fileSystem;
|
||||
_fileSystem = fileSystem;
|
||||
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.");
|
||||
|
||||
FileSystem.DeleteFile(DbFilePath);
|
||||
_fileSystem.DeleteFile(DbFilePath);
|
||||
|
||||
InitializeInternal();
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using Serilog.AspNetCore;
|
||||
using SQLitePCL;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
namespace Jellyfin.Server
|
||||
@ -126,7 +127,11 @@ namespace Jellyfin.Server
|
||||
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
|
||||
#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(
|
||||
appPaths,
|
||||
|
Loading…
x
Reference in New Issue
Block a user