|
|
|
@ -1,7 +1,11 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Data.SQLite;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
|
using NLog;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Datastore
|
|
|
|
|
{
|
|
|
|
@ -14,8 +18,16 @@ namespace NzbDrone.Core.Datastore
|
|
|
|
|
|
|
|
|
|
public class ConnectionStringFactory : IConnectionStringFactory
|
|
|
|
|
{
|
|
|
|
|
public ConnectionStringFactory(IAppFolderInfo appFolderInfo)
|
|
|
|
|
private readonly IDiskProvider _diskProvider;
|
|
|
|
|
private readonly IConfigFileProvider _configFileProvider;
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
public ConnectionStringFactory(IAppFolderInfo appFolderInfo, IDiskProvider diskProvider, IConfigFileProvider configFileProvider, Logger logger)
|
|
|
|
|
{
|
|
|
|
|
_diskProvider = diskProvider;
|
|
|
|
|
_configFileProvider = configFileProvider;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
|
|
|
|
|
MainDbConnectionString = GetConnectionString(appFolderInfo.GetDatabase());
|
|
|
|
|
LogDbConnectionString = GetConnectionString(appFolderInfo.GetLogDatabase());
|
|
|
|
|
}
|
|
|
|
@ -30,23 +42,50 @@ namespace NzbDrone.Core.Datastore
|
|
|
|
|
return connectionBuilder.DataSource;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetConnectionString(string dbPath)
|
|
|
|
|
private string GetConnectionString(string dbPath)
|
|
|
|
|
{
|
|
|
|
|
var connectionBuilder = new SQLiteConnectionStringBuilder();
|
|
|
|
|
|
|
|
|
|
connectionBuilder.DataSource = dbPath;
|
|
|
|
|
connectionBuilder.CacheSize = (int)-10000;
|
|
|
|
|
connectionBuilder.DateTimeKind = DateTimeKind.Utc;
|
|
|
|
|
connectionBuilder.JournalMode = OsInfo.IsOsx ? SQLiteJournalModeEnum.Truncate : SQLiteJournalModeEnum.Wal;
|
|
|
|
|
|
|
|
|
|
connectionBuilder.JournalMode = GetJournalMode(dbPath);
|
|
|
|
|
|
|
|
|
|
if (connectionBuilder.JournalMode == SQLiteJournalModeEnum.Truncate)
|
|
|
|
|
{
|
|
|
|
|
connectionBuilder.Add("Full FSync", true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connectionBuilder.Pooling = true;
|
|
|
|
|
connectionBuilder.Version = 3;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return connectionBuilder.ConnectionString;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SQLiteJournalModeEnum GetJournalMode(string path)
|
|
|
|
|
{
|
|
|
|
|
var driveType = _diskProvider.GetMount(path).DriveType;
|
|
|
|
|
|
|
|
|
|
if (driveType == DriveType.Network || driveType == DriveType.Unknown)
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug("Network filesystem store for application data detected, disabling WAL mode for SQLite");
|
|
|
|
|
return SQLiteJournalModeEnum.Truncate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_configFileProvider.DatabaseJournalMode != (DatabaseJournalType)SQLiteJournalModeEnum.Wal)
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug("DatabaseJournalMode tag detected in config.xml, disabling WAL mode for SQLite");
|
|
|
|
|
return SQLiteJournalModeEnum.Truncate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (OsInfo.IsOsx)
|
|
|
|
|
{
|
|
|
|
|
connectionBuilder.Add("Full FSync", true);
|
|
|
|
|
_logger.Debug("macOS operating system detected, disabling WAL mode for SQLite");
|
|
|
|
|
return SQLiteJournalModeEnum.Truncate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return connectionBuilder.ConnectionString;
|
|
|
|
|
return SQLiteJournalModeEnum.Wal;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|