update connection process

This commit is contained in:
Luke Pulverenti 2016-12-13 03:45:04 -05:00
parent e1b880a5a0
commit 71854c1a09
4 changed files with 92 additions and 80 deletions

View File

@ -129,7 +129,7 @@ namespace Emby.Server.Implementations.Activity
var list = new List<ActivityLogEntry>();
var result = new QueryResult<ActivityLogEntry>();
var statements = PrepareAllSafe(db, string.Join(";", statementTexts.ToArray())).ToList();
var statements = PrepareAllSafe(db, statementTexts).ToList();
using (var statement = statements[0])
{

View File

@ -25,7 +25,7 @@ namespace Emby.Server.Implementations.Data
protected TransactionMode TransactionMode
{
get { return TransactionMode.Immediate; }
get { return TransactionMode.Deferred; }
}
protected TransactionMode ReadTransactionMode
@ -56,6 +56,8 @@ namespace Emby.Server.Implementations.Data
private string _defaultWal;
protected SQLiteDatabaseConnection CreateConnection(bool isReadOnly = false)
{
lock (WriteLock)
{
if (!_versionLogged)
{
@ -95,7 +97,8 @@ namespace Emby.Server.Implementations.Data
var queries = new List<string>
{
//"PRAGMA cache size=-10000"
//"PRAGMA read_uncommitted = true"
//"PRAGMA read_uncommitted = true",
"PRAGMA synchronous=Normal"
};
if (EnableTempStoreMemory)
@ -127,13 +130,14 @@ namespace Emby.Server.Implementations.Data
}
}
else*/
if (queries.Count > 0)
foreach (var query in queries)
{
db.ExecuteAll(string.Join(";", queries.ToArray()));
db.Execute(query);
}
return db;
}
}
public IStatement PrepareStatement(IDatabaseConnection connection, string sql)
{
@ -145,14 +149,14 @@ namespace Emby.Server.Implementations.Data
return connection.PrepareStatement(sql);
}
public List<IStatement> PrepareAll(IDatabaseConnection connection, string sql)
public List<IStatement> PrepareAll(IDatabaseConnection connection, IEnumerable<string> sql)
{
return connection.PrepareAll(sql).ToList();
return PrepareAllSafe(connection, sql);
}
public List<IStatement> PrepareAllSafe(IDatabaseConnection connection, string sql)
public List<IStatement> PrepareAllSafe(IDatabaseConnection connection, IEnumerable<string> sql)
{
return connection.PrepareAll(sql).ToList();
return sql.Select(connection.PrepareStatement).ToList();
}
protected void RunDefaultInitialization(IDatabaseConnection db)
@ -161,6 +165,7 @@ namespace Emby.Server.Implementations.Data
{
"PRAGMA journal_mode=WAL",
"PRAGMA page_size=4096",
"PRAGMA synchronous=Normal"
};
if (EnableTempStoreMemory)
@ -173,6 +178,7 @@ namespace Emby.Server.Implementations.Data
}
db.ExecuteAll(string.Join(";", queries.ToArray()));
Logger.Info("PRAGMA synchronous=" + db.Query("PRAGMA synchronous").SelectScalarString().First());
}
protected virtual bool EnableTempStoreMemory

View File

@ -701,12 +701,12 @@ namespace Emby.Server.Implementations.Data
{
var requiresReset = false;
var statements = PrepareAll(db, string.Join(";", new string[]
var statements = PrepareAllSafe(db, new string[]
{
GetSaveItemCommandText(),
"delete from AncestorIds where ItemId=@ItemId",
"insert into AncestorIds (ItemId, AncestorId, AncestorIdText) values (@ItemId, @AncestorId, @AncestorIdText)"
})).ToList();
}).ToList();
using (var saveItemStatement = statements[0])
{
@ -1258,7 +1258,9 @@ namespace Emby.Server.Implementations.Data
{
using (var connection = CreateConnection(true))
{
using (var statement = PrepareStatementSafe(connection, "select " + string.Join(",", _retriveItemColumns) + " from TypedBaseItems where guid = @guid"))
return connection.RunInTransaction(db =>
{
using (var statement = PrepareStatementSafe(db, "select " + string.Join(",", _retriveItemColumns) + " from TypedBaseItems where guid = @guid"))
{
statement.TryBind("@guid", id);
@ -1267,9 +1269,12 @@ namespace Emby.Server.Implementations.Data
return GetItem(row);
}
}
}
}
return null;
}, ReadTransactionMode);
}
}
}
private BaseItem GetItem(IReadOnlyList<IResultSetValue> reader)
@ -2762,7 +2767,7 @@ namespace Emby.Server.Implementations.Data
return connection.RunInTransaction(db =>
{
var result = new QueryResult<BaseItem>();
var statements = PrepareAllSafe(db, string.Join(";", statementTexts.ToArray()))
var statements = PrepareAllSafe(db, statementTexts)
.ToList();
if (!isReturningZeroItems)
@ -3173,7 +3178,7 @@ namespace Emby.Server.Implementations.Data
{
var result = new QueryResult<Guid>();
var statements = PrepareAllSafe(db, string.Join(";", statementTexts.ToArray()))
var statements = PrepareAllSafe(db, statementTexts)
.ToList();
if (!isReturningZeroItems)
@ -5121,7 +5126,8 @@ namespace Emby.Server.Implementations.Data
var list = new List<Tuple<BaseItem, ItemCounts>>();
var result = new QueryResult<Tuple<BaseItem, ItemCounts>>();
var statements = PrepareAllSafe(db, string.Join(";", statementTexts.ToArray())).ToList();
var statements = PrepareAllSafe(db, statementTexts)
.ToList();
if (!isReturningZeroItems)
{

View File

@ -214,7 +214,7 @@ namespace Emby.Server.Implementations.Security
statementTexts.Add(commandText);
statementTexts.Add("select count (Id) from AccessTokens" + whereTextWithoutPaging);
var statements = PrepareAllSafe(db, string.Join(";", statementTexts.ToArray()))
var statements = PrepareAllSafe(db, statementTexts)
.ToList();
using (var statement = statements[0])