Compare commits
1 Commits
develop
...
sqlite-on-
Author | SHA1 | Date |
---|---|---|
Taloth Saldono | c886a02388 |
|
@ -1,7 +1,10 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Data.SQLite;
|
using System.Data.SQLite;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Common.Disk;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Common.Instrumentation;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Datastore
|
namespace NzbDrone.Core.Datastore
|
||||||
{
|
{
|
||||||
|
@ -14,10 +17,20 @@ namespace NzbDrone.Core.Datastore
|
||||||
|
|
||||||
public class ConnectionStringFactory : IConnectionStringFactory
|
public class ConnectionStringFactory : IConnectionStringFactory
|
||||||
{
|
{
|
||||||
public ConnectionStringFactory(IAppFolderInfo appFolderInfo)
|
private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(ConnectionStringFactory));
|
||||||
|
|
||||||
|
public ConnectionStringFactory(IAppFolderInfo appFolderInfo, IDiskProvider diskProvider)
|
||||||
{
|
{
|
||||||
MainDbConnectionString = GetConnectionString(appFolderInfo.GetNzbDroneDatabase());
|
var mount = diskProvider.GetMount(appFolderInfo.AppDataFolder);
|
||||||
LogDbConnectionString = GetConnectionString(appFolderInfo.GetLogDatabase());
|
var isNetworkDrive = mount.DriveType == System.IO.DriveType.Network;
|
||||||
|
if (isNetworkDrive)
|
||||||
|
{
|
||||||
|
Logger.Warn("AppData folder {0} is located on the network drive {1} using a {2} filesystem. Is highly discouraged to use a SQLite database on network drives and may lead to database corruption.",
|
||||||
|
appFolderInfo.AppDataFolder, mount.RootDirectory, mount.DriveFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
MainDbConnectionString = GetConnectionString(appFolderInfo.GetNzbDroneDatabase(), isNetworkDrive);
|
||||||
|
LogDbConnectionString = GetConnectionString(appFolderInfo.GetLogDatabase(), isNetworkDrive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string MainDbConnectionString { get; private set; }
|
public string MainDbConnectionString { get; private set; }
|
||||||
|
@ -30,14 +43,14 @@ namespace NzbDrone.Core.Datastore
|
||||||
return connectionBuilder.DataSource;
|
return connectionBuilder.DataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetConnectionString(string dbPath)
|
private static string GetConnectionString(string dbPath, bool isNetworkDrive)
|
||||||
{
|
{
|
||||||
var connectionBuilder = new SQLiteConnectionStringBuilder();
|
var connectionBuilder = new SQLiteConnectionStringBuilder();
|
||||||
|
|
||||||
connectionBuilder.DataSource = dbPath;
|
connectionBuilder.DataSource = dbPath;
|
||||||
connectionBuilder.CacheSize = (int)-10.Megabytes();
|
connectionBuilder.CacheSize = (int)-10.Megabytes();
|
||||||
connectionBuilder.DateTimeKind = DateTimeKind.Utc;
|
connectionBuilder.DateTimeKind = DateTimeKind.Utc;
|
||||||
connectionBuilder.JournalMode = OsInfo.IsOsx ? SQLiteJournalModeEnum.Truncate : SQLiteJournalModeEnum.Wal;
|
connectionBuilder.JournalMode = OsInfo.IsOsx || isNetworkDrive ? SQLiteJournalModeEnum.Truncate : SQLiteJournalModeEnum.Wal;
|
||||||
connectionBuilder.Pooling = true;
|
connectionBuilder.Pooling = true;
|
||||||
connectionBuilder.Version = 3;
|
connectionBuilder.Version = 3;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue