Merge pull request #9635 from Bond-009/sql

pull/9645/head
Bond-009 2 years ago committed by GitHub
commit c2b88f1852
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -166,18 +166,6 @@ namespace Emby.Server.Implementations.Data
public IStatement PrepareStatement(IDatabaseConnection connection, string sql) public IStatement PrepareStatement(IDatabaseConnection connection, string sql)
=> connection.PrepareStatement(sql); => connection.PrepareStatement(sql);
public IStatement[] PrepareAll(IDatabaseConnection connection, IReadOnlyList<string> sql)
{
int len = sql.Count;
IStatement[] statements = new IStatement[len];
for (int i = 0; i < len; i++)
{
statements[i] = connection.PrepareStatement(sql[i]);
}
return statements;
}
protected bool TableExists(ManagedConnection connection, string name) protected bool TableExists(ManagedConnection connection, string name)
{ {
return connection.RunInTransaction( return connection.RunInTransaction(

@ -624,14 +624,8 @@ namespace Emby.Server.Implementations.Data
private void SaveItemsInTransaction(IDatabaseConnection db, IEnumerable<(BaseItem Item, List<Guid> AncestorIds, BaseItem TopParent, string UserDataKey, List<string> InheritedTags)> tuples) private void SaveItemsInTransaction(IDatabaseConnection db, IEnumerable<(BaseItem Item, List<Guid> AncestorIds, BaseItem TopParent, string UserDataKey, List<string> InheritedTags)> tuples)
{ {
var statements = PrepareAll(db, new string[] using (var saveItemStatement = PrepareStatement(db, SaveItemCommandText))
{ using (var deleteAncestorsStatement = PrepareStatement(db, "delete from AncestorIds where ItemId=@ItemId"))
SaveItemCommandText,
"delete from AncestorIds where ItemId=@ItemId"
});
using (var saveItemStatement = statements[0])
using (var deleteAncestorsStatement = statements[1])
{ {
var requiresReset = false; var requiresReset = false;
foreach (var tuple in tuples) foreach (var tuple in tuples)
@ -1286,7 +1280,6 @@ namespace Emby.Server.Implementations.Data
CheckDisposed(); CheckDisposed();
using (var connection = GetConnection(true)) using (var connection = GetConnection(true))
{
using (var statement = PrepareStatement(connection, _retrieveItemColumnsSelectQuery)) using (var statement = PrepareStatement(connection, _retrieveItemColumnsSelectQuery))
{ {
statement.TryBind("@guid", id); statement.TryBind("@guid", id);
@ -1296,7 +1289,6 @@ namespace Emby.Server.Implementations.Data
return GetItem(row, new InternalItemsQuery()); return GetItem(row, new InternalItemsQuery());
} }
} }
}
return null; return null;
} }
@ -1972,10 +1964,8 @@ namespace Emby.Server.Implementations.Data
{ {
CheckDisposed(); CheckDisposed();
using (var connection = GetConnection(true))
{
var chapters = new List<ChapterInfo>(); var chapters = new List<ChapterInfo>();
using (var connection = GetConnection(true))
using (var statement = PrepareStatement(connection, "select StartPositionTicks,Name,ImagePath,ImageDateModified from " + ChaptersTableName + " where ItemId = @ItemId order by ChapterIndex asc")) using (var statement = PrepareStatement(connection, "select StartPositionTicks,Name,ImagePath,ImageDateModified from " + ChaptersTableName + " where ItemId = @ItemId order by ChapterIndex asc"))
{ {
statement.TryBind("@ItemId", item.Id); statement.TryBind("@ItemId", item.Id);
@ -1988,7 +1978,6 @@ namespace Emby.Server.Implementations.Data
return chapters; return chapters;
} }
}
/// <inheritdoc /> /// <inheritdoc />
public ChapterInfo GetChapter(BaseItem item, int index) public ChapterInfo GetChapter(BaseItem item, int index)
@ -1996,7 +1985,6 @@ namespace Emby.Server.Implementations.Data
CheckDisposed(); CheckDisposed();
using (var connection = GetConnection(true)) using (var connection = GetConnection(true))
{
using (var statement = PrepareStatement(connection, "select StartPositionTicks,Name,ImagePath,ImageDateModified from " + ChaptersTableName + " where ItemId = @ItemId and ChapterIndex=@ChapterIndex")) using (var statement = PrepareStatement(connection, "select StartPositionTicks,Name,ImagePath,ImageDateModified from " + ChaptersTableName + " where ItemId = @ItemId and ChapterIndex=@ChapterIndex"))
{ {
statement.TryBind("@ItemId", item.Id); statement.TryBind("@ItemId", item.Id);
@ -2007,7 +1995,6 @@ namespace Emby.Server.Implementations.Data
return GetChapter(row, item); return GetChapter(row, item);
} }
} }
}
return null; return null;
} }
@ -2858,13 +2845,10 @@ namespace Emby.Server.Implementations.Data
connection.RunInTransaction( connection.RunInTransaction(
db => db =>
{ {
var itemQueryStatement = PrepareStatement(db, itemQuery);
var totalRecordCountQueryStatement = PrepareStatement(db, totalRecordCountQuery);
if (!isReturningZeroItems) if (!isReturningZeroItems)
{ {
using (new QueryTimeLogger(Logger, itemQuery, "GetItems.ItemQuery")) using (new QueryTimeLogger(Logger, itemQuery, "GetItems.ItemQuery"))
using (var statement = itemQueryStatement) using (var statement = PrepareStatement(db, itemQuery))
{ {
if (EnableJoinUserData(query)) if (EnableJoinUserData(query))
{ {
@ -2899,7 +2883,7 @@ namespace Emby.Server.Implementations.Data
if (query.EnableTotalRecordCount) if (query.EnableTotalRecordCount)
{ {
using (new QueryTimeLogger(Logger, totalRecordCountQuery, "GetItems.TotalRecordCount")) using (new QueryTimeLogger(Logger, totalRecordCountQuery, "GetItems.TotalRecordCount"))
using (var statement = totalRecordCountQueryStatement) using (var statement = PrepareStatement(db, totalRecordCountQuery))
{ {
if (EnableJoinUserData(query)) if (EnableJoinUserData(query))
{ {
@ -4768,9 +4752,8 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
commandText.Append(" LIMIT ").Append(query.Limit); commandText.Append(" LIMIT ").Append(query.Limit);
} }
using (var connection = GetConnection(true))
{
var list = new List<string>(); var list = new List<string>();
using (var connection = GetConnection(true))
using (var statement = PrepareStatement(connection, commandText.ToString())) using (var statement = PrepareStatement(connection, commandText.ToString()))
{ {
// Run this again to bind the params // Run this again to bind the params
@ -4784,7 +4767,6 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
return list; return list;
} }
}
public List<PersonInfo> GetPeople(InternalPeopleQuery query) public List<PersonInfo> GetPeople(InternalPeopleQuery query)
{ {
@ -4808,10 +4790,8 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
commandText += " LIMIT " + query.Limit; commandText += " LIMIT " + query.Limit;
} }
using (var connection = GetConnection(true))
{
var list = new List<PersonInfo>(); var list = new List<PersonInfo>();
using (var connection = GetConnection(true))
using (var statement = PrepareStatement(connection, commandText)) using (var statement = PrepareStatement(connection, commandText))
{ {
// Run this again to bind the params // Run this again to bind the params
@ -4825,7 +4805,6 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
return list; return list;
} }
}
private List<string> GetPeopleWhereClauses(InternalPeopleQuery query, IStatement statement) private List<string> GetPeopleWhereClauses(InternalPeopleQuery query, IStatement statement)
{ {

Loading…
Cancel
Save