|
|
|
@ -108,37 +108,49 @@ namespace Emby.Server.Implementations.Data
|
|
|
|
|
|
|
|
|
|
var db = SQLite3.Open(DbFilePath, connectionFlags, null);
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(_defaultWal))
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_defaultWal = db.Query("PRAGMA journal_mode").SelectScalarString().First();
|
|
|
|
|
if (string.IsNullOrWhiteSpace(_defaultWal))
|
|
|
|
|
{
|
|
|
|
|
_defaultWal = db.Query("PRAGMA journal_mode").SelectScalarString().First();
|
|
|
|
|
|
|
|
|
|
Logger.Info("Default journal_mode for {0} is {1}", DbFilePath, _defaultWal);
|
|
|
|
|
}
|
|
|
|
|
Logger.Info("Default journal_mode for {0} is {1}", DbFilePath, _defaultWal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var queries = new List<string>
|
|
|
|
|
{
|
|
|
|
|
//"PRAGMA cache size=-10000"
|
|
|
|
|
//"PRAGMA read_uncommitted = true",
|
|
|
|
|
"PRAGMA synchronous=Normal"
|
|
|
|
|
};
|
|
|
|
|
var queries = new List<string>
|
|
|
|
|
{
|
|
|
|
|
//"PRAGMA cache size=-10000"
|
|
|
|
|
//"PRAGMA read_uncommitted = true",
|
|
|
|
|
"PRAGMA synchronous=Normal"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (CacheSize.HasValue)
|
|
|
|
|
{
|
|
|
|
|
queries.Add("PRAGMA cache_size=" + CacheSize.Value.ToString(CultureInfo.InvariantCulture));
|
|
|
|
|
}
|
|
|
|
|
if (CacheSize.HasValue)
|
|
|
|
|
{
|
|
|
|
|
queries.Add("PRAGMA cache_size=" + CacheSize.Value.ToString(CultureInfo.InvariantCulture));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (EnableTempStoreMemory)
|
|
|
|
|
{
|
|
|
|
|
queries.Add("PRAGMA temp_store = memory");
|
|
|
|
|
if (EnableTempStoreMemory)
|
|
|
|
|
{
|
|
|
|
|
queries.Add("PRAGMA temp_store = memory");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
queries.Add("PRAGMA temp_store = file");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var query in queries)
|
|
|
|
|
{
|
|
|
|
|
db.Execute(query);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
queries.Add("PRAGMA temp_store = file");
|
|
|
|
|
}
|
|
|
|
|
using (db)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
foreach (var query in queries)
|
|
|
|
|
{
|
|
|
|
|
db.Execute(query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_connection = new ManagedConnection(db, false);
|
|
|
|
@ -265,29 +277,34 @@ namespace Emby.Server.Implementations.Data
|
|
|
|
|
{
|
|
|
|
|
if (dispose)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
DisposeConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DisposeConnection()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
lock (_disposeLock)
|
|
|
|
|
{
|
|
|
|
|
lock (_disposeLock)
|
|
|
|
|
using (WriteLock.Write())
|
|
|
|
|
{
|
|
|
|
|
using (WriteLock.Write())
|
|
|
|
|
if (_connection != null)
|
|
|
|
|
{
|
|
|
|
|
if (_connection != null)
|
|
|
|
|
using (_connection)
|
|
|
|
|
{
|
|
|
|
|
using (_connection)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
_connection = null;
|
|
|
|
|
_connection.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CloseConnection();
|
|
|
|
|
_connection = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CloseConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException("Error disposing database", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException("Error disposing database", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|