|
@@ -127,10 +127,19 @@ namespace Emby.Server.Implementations.Data
|
|
{
|
|
{
|
|
_connection = CreateConnection(false);
|
|
_connection = CreateConnection(false);
|
|
|
|
|
|
|
|
+ _connection.ExecuteAll(string.Join(";", new[]
|
|
|
|
+ {
|
|
|
|
+ "pragma default_temp_store = memory",
|
|
|
|
+ "pragma default_synchronous=Normal",
|
|
|
|
+ "pragma temp_store = memory",
|
|
|
|
+ "pragma synchronous=Normal",
|
|
|
|
+ }));
|
|
|
|
+
|
|
var createMediaStreamsTableCommand
|
|
var createMediaStreamsTableCommand
|
|
= "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, CodecTag TEXT NULL, Comment TEXT NULL, NalLengthSize TEXT NULL, IsAvc BIT NULL, Title TEXT NULL, TimeBase TEXT NULL, CodecTimeBase TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))";
|
|
= "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, CodecTag TEXT NULL, Comment TEXT NULL, NalLengthSize TEXT NULL, IsAvc BIT NULL, Title TEXT NULL, TimeBase TEXT NULL, CodecTimeBase TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))";
|
|
|
|
|
|
string[] queries = {
|
|
string[] queries = {
|
|
|
|
+ "PRAGMA locking_mode=NORMAL",
|
|
|
|
|
|
"create table if not exists TypedBaseItems (guid GUID primary key NOT NULL, type TEXT NOT NULL, data BLOB NULL, ParentId GUID NULL, Path TEXT NULL)",
|
|
"create table if not exists TypedBaseItems (guid GUID primary key NOT NULL, type TEXT NOT NULL, data BLOB NULL, ParentId GUID NULL, Path TEXT NULL)",
|
|
|
|
|
|
@@ -344,25 +353,26 @@ namespace Emby.Server.Implementations.Data
|
|
|
|
|
|
_connection.RunQueries(postQueries);
|
|
_connection.RunQueries(postQueries);
|
|
|
|
|
|
- SqliteExtensions.Attach(_connection, Path.Combine(_config.ApplicationPaths.DataPath, "userdata_v2.db"), "UserDataDb");
|
|
|
|
- userDataRepo.Initialize(_connection, WriteLock);
|
|
|
|
|
|
+ //SqliteExtensions.Attach(_connection, Path.Combine(_config.ApplicationPaths.DataPath, "userdata_v2.db"), "UserDataDb");
|
|
|
|
+ userDataRepo.Initialize(WriteLock);
|
|
//await Vacuum(_connection).ConfigureAwait(false);
|
|
//await Vacuum(_connection).ConfigureAwait(false);
|
|
}
|
|
}
|
|
|
|
|
|
- protected override bool EnableConnectionPooling
|
|
|
|
- {
|
|
|
|
- get
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
- protected override bool EnableExclusiveMode
|
|
|
|
|
|
+ private SQLiteDatabaseConnection CreateConnection(bool readOnly, bool attachUserdata)
|
|
{
|
|
{
|
|
- get
|
|
|
|
|
|
+ Action<SQLiteDatabaseConnection> onConnect = null;
|
|
|
|
+
|
|
|
|
+ if (attachUserdata)
|
|
{
|
|
{
|
|
- return true;
|
|
|
|
|
|
+ onConnect =
|
|
|
|
+ c => SqliteExtensions.Attach(c, Path.Combine(_config.ApplicationPaths.DataPath, "userdata_v2.db"),
|
|
|
|
+ "UserDataDb");
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ var conn = CreateConnection(readOnly, onConnect);
|
|
|
|
+
|
|
|
|
+ return conn;
|
|
}
|
|
}
|
|
|
|
|
|
private readonly string[] _retriveItemColumns =
|
|
private readonly string[] _retriveItemColumns =
|
|
@@ -635,12 +645,15 @@ namespace Emby.Server.Implementations.Data
|
|
|
|
|
|
CheckDisposed();
|
|
CheckDisposed();
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection())
|
|
{
|
|
{
|
|
- _connection.RunInTransaction(db =>
|
|
|
|
|
|
+ using (WriteLock.Write())
|
|
{
|
|
{
|
|
- SaveItemsInTranscation(db, items);
|
|
|
|
- });
|
|
|
|
|
|
+ connection.RunInTransaction(db =>
|
|
|
|
+ {
|
|
|
|
+ SaveItemsInTranscation(db, items);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1170,15 +1183,18 @@ namespace Emby.Server.Implementations.Data
|
|
|
|
|
|
CheckDisposed();
|
|
CheckDisposed();
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection(true))
|
|
{
|
|
{
|
|
- using (var statement = _connection.PrepareStatement("select " + string.Join(",", _retriveItemColumns) + " from TypedBaseItems where guid = @guid"))
|
|
|
|
|
|
+ using (WriteLock.Read())
|
|
{
|
|
{
|
|
- statement.TryBind("@guid", id);
|
|
|
|
-
|
|
|
|
- foreach (var row in statement.ExecuteQuery())
|
|
|
|
|
|
+ using (var statement = connection.PrepareStatement("select " + string.Join(",", _retriveItemColumns) + " from TypedBaseItems where guid = @guid"))
|
|
{
|
|
{
|
|
- return GetItem(row);
|
|
|
|
|
|
+ statement.TryBind("@guid", id);
|
|
|
|
+
|
|
|
|
+ foreach (var row in statement.ExecuteQuery())
|
|
|
|
+ {
|
|
|
|
+ return GetItem(row);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1976,15 +1992,18 @@ namespace Emby.Server.Implementations.Data
|
|
|
|
|
|
var list = new List<ChapterInfo>();
|
|
var list = new List<ChapterInfo>();
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection(true))
|
|
{
|
|
{
|
|
- using (var statement = _connection.PrepareStatement("select StartPositionTicks,Name,ImagePath,ImageDateModified from " + ChaptersTableName + " where ItemId = @ItemId order by ChapterIndex asc"))
|
|
|
|
|
|
+ using (WriteLock.Read())
|
|
{
|
|
{
|
|
- statement.TryBind("@ItemId", id);
|
|
|
|
-
|
|
|
|
- foreach (var row in statement.ExecuteQuery())
|
|
|
|
|
|
+ using (var statement = connection.PrepareStatement("select StartPositionTicks,Name,ImagePath,ImageDateModified from " + ChaptersTableName + " where ItemId = @ItemId order by ChapterIndex asc"))
|
|
{
|
|
{
|
|
- list.Add(GetChapter(row));
|
|
|
|
|
|
+ statement.TryBind("@ItemId", id);
|
|
|
|
+
|
|
|
|
+ foreach (var row in statement.ExecuteQuery())
|
|
|
|
+ {
|
|
|
|
+ list.Add(GetChapter(row));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -2007,16 +2026,19 @@ namespace Emby.Server.Implementations.Data
|
|
throw new ArgumentNullException("id");
|
|
throw new ArgumentNullException("id");
|
|
}
|
|
}
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection(true))
|
|
{
|
|
{
|
|
- using (var statement = _connection.PrepareStatement("select StartPositionTicks,Name,ImagePath,ImageDateModified from " + ChaptersTableName + " where ItemId = @ItemId and ChapterIndex=@ChapterIndex"))
|
|
|
|
|
|
+ using (WriteLock.Read())
|
|
{
|
|
{
|
|
- statement.TryBind("@ItemId", id);
|
|
|
|
- statement.TryBind("@ChapterIndex", index);
|
|
|
|
-
|
|
|
|
- foreach (var row in statement.ExecuteQuery())
|
|
|
|
|
|
+ using (var statement = connection.PrepareStatement("select StartPositionTicks,Name,ImagePath,ImageDateModified from " + ChaptersTableName + " where ItemId = @ItemId and ChapterIndex=@ChapterIndex"))
|
|
{
|
|
{
|
|
- return GetChapter(row);
|
|
|
|
|
|
+ statement.TryBind("@ItemId", id);
|
|
|
|
+ statement.TryBind("@ChapterIndex", index);
|
|
|
|
+
|
|
|
|
+ foreach (var row in statement.ExecuteQuery())
|
|
|
|
+ {
|
|
|
|
+ return GetChapter(row);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -2085,35 +2107,38 @@ namespace Emby.Server.Implementations.Data
|
|
|
|
|
|
var index = 0;
|
|
var index = 0;
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection())
|
|
{
|
|
{
|
|
- _connection.RunInTransaction(db =>
|
|
|
|
|
|
+ using (WriteLock.Write())
|
|
{
|
|
{
|
|
- // First delete chapters
|
|
|
|
- _connection.Execute("delete from " + ChaptersTableName + " where ItemId=@ItemId", id.ToGuidParamValue());
|
|
|
|
-
|
|
|
|
- using (var saveChapterStatement = db.PrepareStatement("replace into " + ChaptersTableName + " (ItemId, ChapterIndex, StartPositionTicks, Name, ImagePath, ImageDateModified) values (@ItemId, @ChapterIndex, @StartPositionTicks, @Name, @ImagePath, @ImageDateModified)"))
|
|
|
|
|
|
+ connection.RunInTransaction(db =>
|
|
{
|
|
{
|
|
- foreach (var chapter in chapters)
|
|
|
|
|
|
+ // First delete chapters
|
|
|
|
+ db.Execute("delete from " + ChaptersTableName + " where ItemId=@ItemId", id.ToGuidParamValue());
|
|
|
|
+
|
|
|
|
+ using (var saveChapterStatement = db.PrepareStatement("replace into " + ChaptersTableName + " (ItemId, ChapterIndex, StartPositionTicks, Name, ImagePath, ImageDateModified) values (@ItemId, @ChapterIndex, @StartPositionTicks, @Name, @ImagePath, @ImageDateModified)"))
|
|
{
|
|
{
|
|
- if (index > 0)
|
|
|
|
|
|
+ foreach (var chapter in chapters)
|
|
{
|
|
{
|
|
- saveChapterStatement.Reset();
|
|
|
|
- }
|
|
|
|
|
|
+ if (index > 0)
|
|
|
|
+ {
|
|
|
|
+ saveChapterStatement.Reset();
|
|
|
|
+ }
|
|
|
|
|
|
- saveChapterStatement.TryBind("@ItemId", id.ToGuidParamValue());
|
|
|
|
- saveChapterStatement.TryBind("@ChapterIndex", index);
|
|
|
|
- saveChapterStatement.TryBind("@StartPositionTicks", chapter.StartPositionTicks);
|
|
|
|
- saveChapterStatement.TryBind("@Name", chapter.Name);
|
|
|
|
- saveChapterStatement.TryBind("@ImagePath", chapter.ImagePath);
|
|
|
|
- saveChapterStatement.TryBind("@ImageDateModified", chapter.ImageDateModified);
|
|
|
|
|
|
+ saveChapterStatement.TryBind("@ItemId", id.ToGuidParamValue());
|
|
|
|
+ saveChapterStatement.TryBind("@ChapterIndex", index);
|
|
|
|
+ saveChapterStatement.TryBind("@StartPositionTicks", chapter.StartPositionTicks);
|
|
|
|
+ saveChapterStatement.TryBind("@Name", chapter.Name);
|
|
|
|
+ saveChapterStatement.TryBind("@ImagePath", chapter.ImagePath);
|
|
|
|
+ saveChapterStatement.TryBind("@ImageDateModified", chapter.ImageDateModified);
|
|
|
|
|
|
- saveChapterStatement.MoveNext();
|
|
|
|
|
|
+ saveChapterStatement.MoveNext();
|
|
|
|
|
|
- index++;
|
|
|
|
|
|
+ index++;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2383,31 +2408,34 @@ namespace Emby.Server.Implementations.Data
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection(true, EnableJoinUserData(query)))
|
|
{
|
|
{
|
|
- using (var statement = _connection.PrepareStatement(commandText))
|
|
|
|
|
|
+ using (WriteLock.Read())
|
|
{
|
|
{
|
|
- if (EnableJoinUserData(query))
|
|
|
|
|
|
+ using (var statement = connection.PrepareStatement(commandText))
|
|
{
|
|
{
|
|
- statement.TryBind("@UserId", query.User.Id);
|
|
|
|
- }
|
|
|
|
|
|
+ if (EnableJoinUserData(query))
|
|
|
|
+ {
|
|
|
|
+ statement.TryBind("@UserId", query.User.Id);
|
|
|
|
+ }
|
|
|
|
|
|
- BindSimilarParams(query, statement);
|
|
|
|
|
|
+ BindSimilarParams(query, statement);
|
|
|
|
|
|
- // Running this again will bind the params
|
|
|
|
- GetWhereClauses(query, statement);
|
|
|
|
|
|
+ // Running this again will bind the params
|
|
|
|
+ GetWhereClauses(query, statement);
|
|
|
|
|
|
- foreach (var row in statement.ExecuteQuery())
|
|
|
|
- {
|
|
|
|
- var item = GetItem(row, query);
|
|
|
|
- if (item != null)
|
|
|
|
|
|
+ foreach (var row in statement.ExecuteQuery())
|
|
{
|
|
{
|
|
- list.Add(item);
|
|
|
|
|
|
+ var item = GetItem(row, query);
|
|
|
|
+ if (item != null)
|
|
|
|
+ {
|
|
|
|
+ list.Add(item);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- LogQueryTime("GetItemList", commandText, now);
|
|
|
|
|
|
+ LogQueryTime("GetItemList", commandText, now);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// Hack for right now since we currently don't support filtering out these duplicates within a query
|
|
// Hack for right now since we currently don't support filtering out these duplicates within a query
|
|
@@ -2548,72 +2576,75 @@ namespace Emby.Server.Implementations.Data
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection(true, EnableJoinUserData(query)))
|
|
{
|
|
{
|
|
- var totalRecordCount = 0;
|
|
|
|
- var isReturningZeroItems = query.Limit.HasValue && query.Limit <= 0;
|
|
|
|
-
|
|
|
|
- if (!isReturningZeroItems)
|
|
|
|
|
|
+ using (WriteLock.Read())
|
|
{
|
|
{
|
|
- using (var statement = _connection.PrepareStatement(commandText))
|
|
|
|
|
|
+ var totalRecordCount = 0;
|
|
|
|
+ var isReturningZeroItems = query.Limit.HasValue && query.Limit <= 0;
|
|
|
|
+
|
|
|
|
+ if (!isReturningZeroItems)
|
|
{
|
|
{
|
|
- if (EnableJoinUserData(query))
|
|
|
|
|
|
+ using (var statement = connection.PrepareStatement(commandText))
|
|
{
|
|
{
|
|
- statement.TryBind("@UserId", query.User.Id);
|
|
|
|
- }
|
|
|
|
|
|
+ if (EnableJoinUserData(query))
|
|
|
|
+ {
|
|
|
|
+ statement.TryBind("@UserId", query.User.Id);
|
|
|
|
+ }
|
|
|
|
|
|
- BindSimilarParams(query, statement);
|
|
|
|
|
|
+ BindSimilarParams(query, statement);
|
|
|
|
|
|
- // Running this again will bind the params
|
|
|
|
- GetWhereClauses(query, statement);
|
|
|
|
|
|
+ // Running this again will bind the params
|
|
|
|
+ GetWhereClauses(query, statement);
|
|
|
|
|
|
- foreach (var row in statement.ExecuteQuery())
|
|
|
|
- {
|
|
|
|
- var item = GetItem(row, query);
|
|
|
|
- if (item != null)
|
|
|
|
|
|
+ foreach (var row in statement.ExecuteQuery())
|
|
{
|
|
{
|
|
- list.Add(item);
|
|
|
|
|
|
+ var item = GetItem(row, query);
|
|
|
|
+ if (item != null)
|
|
|
|
+ {
|
|
|
|
+ list.Add(item);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- commandText = string.Empty;
|
|
|
|
|
|
+ commandText = string.Empty;
|
|
|
|
|
|
- if (EnableGroupByPresentationUniqueKey(query))
|
|
|
|
- {
|
|
|
|
- commandText += " select count (distinct PresentationUniqueKey)" + GetFromText();
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- commandText += " select count (guid)" + GetFromText();
|
|
|
|
- }
|
|
|
|
|
|
+ if (EnableGroupByPresentationUniqueKey(query))
|
|
|
|
+ {
|
|
|
|
+ commandText += " select count (distinct PresentationUniqueKey)" + GetFromText();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ commandText += " select count (guid)" + GetFromText();
|
|
|
|
+ }
|
|
|
|
|
|
- commandText += GetJoinUserDataText(query);
|
|
|
|
- commandText += whereTextWithoutPaging;
|
|
|
|
|
|
+ commandText += GetJoinUserDataText(query);
|
|
|
|
+ commandText += whereTextWithoutPaging;
|
|
|
|
|
|
- using (var statement = _connection.PrepareStatement(commandText))
|
|
|
|
- {
|
|
|
|
- if (EnableJoinUserData(query))
|
|
|
|
|
|
+ using (var statement = connection.PrepareStatement(commandText))
|
|
{
|
|
{
|
|
- statement.TryBind("@UserId", query.User.Id);
|
|
|
|
- }
|
|
|
|
|
|
+ if (EnableJoinUserData(query))
|
|
|
|
+ {
|
|
|
|
+ statement.TryBind("@UserId", query.User.Id);
|
|
|
|
+ }
|
|
|
|
|
|
- BindSimilarParams(query, statement);
|
|
|
|
|
|
+ BindSimilarParams(query, statement);
|
|
|
|
|
|
- // Running this again will bind the params
|
|
|
|
- GetWhereClauses(query, statement);
|
|
|
|
|
|
+ // Running this again will bind the params
|
|
|
|
+ GetWhereClauses(query, statement);
|
|
|
|
|
|
- totalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
|
|
|
|
- }
|
|
|
|
|
|
+ totalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
|
|
|
|
+ }
|
|
|
|
|
|
- LogQueryTime("GetItems", commandText, now);
|
|
|
|
|
|
+ LogQueryTime("GetItems", commandText, now);
|
|
|
|
|
|
- return new QueryResult<BaseItem>()
|
|
|
|
- {
|
|
|
|
- Items = list.ToArray(),
|
|
|
|
- TotalRecordCount = totalRecordCount
|
|
|
|
- };
|
|
|
|
|
|
+ return new QueryResult<BaseItem>()
|
|
|
|
+ {
|
|
|
|
+ Items = list.ToArray(),
|
|
|
|
+ TotalRecordCount = totalRecordCount
|
|
|
|
+ };
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2774,29 +2805,32 @@ namespace Emby.Server.Implementations.Data
|
|
|
|
|
|
var list = new List<Guid>();
|
|
var list = new List<Guid>();
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection(true, EnableJoinUserData(query)))
|
|
{
|
|
{
|
|
- using (var statement = _connection.PrepareStatement(commandText))
|
|
|
|
|
|
+ using (WriteLock.Read())
|
|
{
|
|
{
|
|
- if (EnableJoinUserData(query))
|
|
|
|
|
|
+ using (var statement = connection.PrepareStatement(commandText))
|
|
{
|
|
{
|
|
- statement.TryBind("@UserId", query.User.Id);
|
|
|
|
- }
|
|
|
|
|
|
+ if (EnableJoinUserData(query))
|
|
|
|
+ {
|
|
|
|
+ statement.TryBind("@UserId", query.User.Id);
|
|
|
|
+ }
|
|
|
|
|
|
- BindSimilarParams(query, statement);
|
|
|
|
|
|
+ BindSimilarParams(query, statement);
|
|
|
|
|
|
- // Running this again will bind the params
|
|
|
|
- GetWhereClauses(query, statement);
|
|
|
|
|
|
+ // Running this again will bind the params
|
|
|
|
+ GetWhereClauses(query, statement);
|
|
|
|
|
|
- foreach (var row in statement.ExecuteQuery())
|
|
|
|
- {
|
|
|
|
- list.Add(row[0].ReadGuid());
|
|
|
|
|
|
+ foreach (var row in statement.ExecuteQuery())
|
|
|
|
+ {
|
|
|
|
+ list.Add(row[0].ReadGuid());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- LogQueryTime("GetItemList", commandText, now);
|
|
|
|
|
|
+ LogQueryTime("GetItemList", commandText, now);
|
|
|
|
|
|
- return list;
|
|
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2842,34 +2876,37 @@ namespace Emby.Server.Implementations.Data
|
|
|
|
|
|
var list = new List<Tuple<Guid, string>>();
|
|
var list = new List<Tuple<Guid, string>>();
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection(true, EnableJoinUserData(query)))
|
|
{
|
|
{
|
|
- using (var statement = _connection.PrepareStatement(commandText))
|
|
|
|
|
|
+ using (WriteLock.Read())
|
|
{
|
|
{
|
|
- if (EnableJoinUserData(query))
|
|
|
|
|
|
+ using (var statement = connection.PrepareStatement(commandText))
|
|
{
|
|
{
|
|
- statement.TryBind("@UserId", query.User.Id);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Running this again will bind the params
|
|
|
|
- GetWhereClauses(query, statement);
|
|
|
|
|
|
+ if (EnableJoinUserData(query))
|
|
|
|
+ {
|
|
|
|
+ statement.TryBind("@UserId", query.User.Id);
|
|
|
|
+ }
|
|
|
|
|
|
- foreach (var row in statement.ExecuteQuery())
|
|
|
|
- {
|
|
|
|
- var id = row.GetGuid(0);
|
|
|
|
- string path = null;
|
|
|
|
|
|
+ // Running this again will bind the params
|
|
|
|
+ GetWhereClauses(query, statement);
|
|
|
|
|
|
- if (!row.IsDBNull(1))
|
|
|
|
|
|
+ foreach (var row in statement.ExecuteQuery())
|
|
{
|
|
{
|
|
- path = row.GetString(1);
|
|
|
|
|
|
+ var id = row.GetGuid(0);
|
|
|
|
+ string path = null;
|
|
|
|
+
|
|
|
|
+ if (!row.IsDBNull(1))
|
|
|
|
+ {
|
|
|
|
+ path = row.GetString(1);
|
|
|
|
+ }
|
|
|
|
+ list.Add(new Tuple<Guid, string>(id, path));
|
|
}
|
|
}
|
|
- list.Add(new Tuple<Guid, string>(id, path));
|
|
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- LogQueryTime("GetItemIdsWithPath", commandText, now);
|
|
|
|
|
|
+ LogQueryTime("GetItemIdsWithPath", commandText, now);
|
|
|
|
|
|
- return list;
|
|
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2928,64 +2965,67 @@ namespace Emby.Server.Implementations.Data
|
|
|
|
|
|
var list = new List<Guid>();
|
|
var list = new List<Guid>();
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection(true, EnableJoinUserData(query)))
|
|
{
|
|
{
|
|
- var totalRecordCount = 0;
|
|
|
|
-
|
|
|
|
- using (var statement = _connection.PrepareStatement(commandText))
|
|
|
|
|
|
+ using (WriteLock.Read())
|
|
{
|
|
{
|
|
- if (EnableJoinUserData(query))
|
|
|
|
|
|
+ var totalRecordCount = 0;
|
|
|
|
+
|
|
|
|
+ using (var statement = connection.PrepareStatement(commandText))
|
|
{
|
|
{
|
|
- statement.TryBind("@UserId", query.User.Id);
|
|
|
|
- }
|
|
|
|
|
|
+ if (EnableJoinUserData(query))
|
|
|
|
+ {
|
|
|
|
+ statement.TryBind("@UserId", query.User.Id);
|
|
|
|
+ }
|
|
|
|
|
|
- BindSimilarParams(query, statement);
|
|
|
|
|
|
+ BindSimilarParams(query, statement);
|
|
|
|
|
|
- // Running this again will bind the params
|
|
|
|
- GetWhereClauses(query, statement);
|
|
|
|
|
|
+ // Running this again will bind the params
|
|
|
|
+ GetWhereClauses(query, statement);
|
|
|
|
|
|
- foreach (var row in statement.ExecuteQuery())
|
|
|
|
- {
|
|
|
|
- list.Add(row[0].ReadGuid());
|
|
|
|
|
|
+ foreach (var row in statement.ExecuteQuery())
|
|
|
|
+ {
|
|
|
|
+ list.Add(row[0].ReadGuid());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- commandText = string.Empty;
|
|
|
|
|
|
+ commandText = string.Empty;
|
|
|
|
|
|
- if (EnableGroupByPresentationUniqueKey(query))
|
|
|
|
- {
|
|
|
|
- commandText += " select count (distinct PresentationUniqueKey)" + GetFromText();
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- commandText += " select count (guid)" + GetFromText();
|
|
|
|
- }
|
|
|
|
|
|
+ if (EnableGroupByPresentationUniqueKey(query))
|
|
|
|
+ {
|
|
|
|
+ commandText += " select count (distinct PresentationUniqueKey)" + GetFromText();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ commandText += " select count (guid)" + GetFromText();
|
|
|
|
+ }
|
|
|
|
|
|
- commandText += GetJoinUserDataText(query);
|
|
|
|
- commandText += whereTextWithoutPaging;
|
|
|
|
|
|
+ commandText += GetJoinUserDataText(query);
|
|
|
|
+ commandText += whereTextWithoutPaging;
|
|
|
|
|
|
- using (var statement = _connection.PrepareStatement(commandText))
|
|
|
|
- {
|
|
|
|
- if (EnableJoinUserData(query))
|
|
|
|
|
|
+ using (var statement = connection.PrepareStatement(commandText))
|
|
{
|
|
{
|
|
- statement.TryBind("@UserId", query.User.Id);
|
|
|
|
- }
|
|
|
|
|
|
+ if (EnableJoinUserData(query))
|
|
|
|
+ {
|
|
|
|
+ statement.TryBind("@UserId", query.User.Id);
|
|
|
|
+ }
|
|
|
|
|
|
- BindSimilarParams(query, statement);
|
|
|
|
|
|
+ BindSimilarParams(query, statement);
|
|
|
|
|
|
- // Running this again will bind the params
|
|
|
|
- GetWhereClauses(query, statement);
|
|
|
|
|
|
+ // Running this again will bind the params
|
|
|
|
+ GetWhereClauses(query, statement);
|
|
|
|
|
|
- totalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
|
|
|
|
- }
|
|
|
|
|
|
+ totalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
|
|
|
|
+ }
|
|
|
|
|
|
- LogQueryTime("GetItemIds", commandText, now);
|
|
|
|
|
|
+ LogQueryTime("GetItemIds", commandText, now);
|
|
|
|
|
|
- return new QueryResult<Guid>()
|
|
|
|
- {
|
|
|
|
- Items = list.ToArray(),
|
|
|
|
- TotalRecordCount = totalRecordCount
|
|
|
|
- };
|
|
|
|
|
|
+ return new QueryResult<Guid>()
|
|
|
|
+ {
|
|
|
|
+ Items = list.ToArray(),
|
|
|
|
+ TotalRecordCount = totalRecordCount
|
|
|
|
+ };
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -4289,33 +4329,36 @@ namespace Emby.Server.Implementations.Data
|
|
|
|
|
|
var commandText = "select Guid,InheritedTags,(select group_concat(Tags, '|') from TypedBaseItems where (guid=outer.guid) OR (guid in (Select AncestorId from AncestorIds where ItemId=Outer.guid))) as NewInheritedTags from typedbaseitems as Outer where NewInheritedTags <> InheritedTags";
|
|
var commandText = "select Guid,InheritedTags,(select group_concat(Tags, '|') from TypedBaseItems where (guid=outer.guid) OR (guid in (Select AncestorId from AncestorIds where ItemId=Outer.guid))) as NewInheritedTags from typedbaseitems as Outer where NewInheritedTags <> InheritedTags";
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection())
|
|
{
|
|
{
|
|
- foreach (var row in _connection.Query(commandText))
|
|
|
|
|
|
+ using (WriteLock.Write())
|
|
{
|
|
{
|
|
- var id = row.GetGuid(0);
|
|
|
|
- string value = row.IsDBNull(2) ? null : row.GetString(2);
|
|
|
|
|
|
+ foreach (var row in connection.Query(commandText))
|
|
|
|
+ {
|
|
|
|
+ var id = row.GetGuid(0);
|
|
|
|
+ string value = row.IsDBNull(2) ? null : row.GetString(2);
|
|
|
|
|
|
- newValues.Add(new Tuple<Guid, string>(id, value));
|
|
|
|
- }
|
|
|
|
|
|
+ newValues.Add(new Tuple<Guid, string>(id, value));
|
|
|
|
+ }
|
|
|
|
|
|
- Logger.Debug("UpdateInheritedTags - {0} rows", newValues.Count);
|
|
|
|
- if (newValues.Count == 0)
|
|
|
|
- {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ Logger.Debug("UpdateInheritedTags - {0} rows", newValues.Count);
|
|
|
|
+ if (newValues.Count == 0)
|
|
|
|
+ {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
- // write lock here
|
|
|
|
- using (var statement = _connection.PrepareStatement("Update TypedBaseItems set InheritedTags=@InheritedTags where Guid=@Guid"))
|
|
|
|
- {
|
|
|
|
- foreach (var item in newValues)
|
|
|
|
|
|
+ // write lock here
|
|
|
|
+ using (var statement = connection.PrepareStatement("Update TypedBaseItems set InheritedTags=@InheritedTags where Guid=@Guid"))
|
|
{
|
|
{
|
|
- var paramList = new List<object>();
|
|
|
|
|
|
+ foreach (var item in newValues)
|
|
|
|
+ {
|
|
|
|
+ var paramList = new List<object>();
|
|
|
|
|
|
- paramList.Add(item.Item1);
|
|
|
|
- paramList.Add(item.Item2);
|
|
|
|
|
|
+ paramList.Add(item.Item1);
|
|
|
|
+ paramList.Add(item.Item2);
|
|
|
|
|
|
- statement.Execute(paramList.ToArray());
|
|
|
|
|
|
+ statement.Execute(paramList.ToArray());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -4360,28 +4403,31 @@ namespace Emby.Server.Implementations.Data
|
|
|
|
|
|
CheckDisposed();
|
|
CheckDisposed();
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection())
|
|
{
|
|
{
|
|
- _connection.RunInTransaction(db =>
|
|
|
|
|
|
+ using (WriteLock.Write())
|
|
{
|
|
{
|
|
- // Delete people
|
|
|
|
- ExecuteWithSingleParam(db, "delete from People where ItemId=@Id", id.ToGuidParamValue());
|
|
|
|
|
|
+ connection.RunInTransaction(db =>
|
|
|
|
+ {
|
|
|
|
+ // Delete people
|
|
|
|
+ ExecuteWithSingleParam(db, "delete from People where ItemId=@Id", id.ToGuidParamValue());
|
|
|
|
|
|
- // Delete chapters
|
|
|
|
- ExecuteWithSingleParam(db, "delete from " + ChaptersTableName + " where ItemId=@Id", id.ToGuidParamValue());
|
|
|
|
|
|
+ // Delete chapters
|
|
|
|
+ ExecuteWithSingleParam(db, "delete from " + ChaptersTableName + " where ItemId=@Id", id.ToGuidParamValue());
|
|
|
|
|
|
- // Delete media streams
|
|
|
|
- ExecuteWithSingleParam(db, "delete from mediastreams where ItemId=@Id", id.ToGuidParamValue());
|
|
|
|
|
|
+ // Delete media streams
|
|
|
|
+ ExecuteWithSingleParam(db, "delete from mediastreams where ItemId=@Id", id.ToGuidParamValue());
|
|
|
|
|
|
- // Delete ancestors
|
|
|
|
- ExecuteWithSingleParam(db, "delete from AncestorIds where ItemId=@Id", id.ToGuidParamValue());
|
|
|
|
|
|
+ // Delete ancestors
|
|
|
|
+ ExecuteWithSingleParam(db, "delete from AncestorIds where ItemId=@Id", id.ToGuidParamValue());
|
|
|
|
|
|
- // Delete item values
|
|
|
|
- ExecuteWithSingleParam(db, "delete from ItemValues where ItemId=@Id", id.ToGuidParamValue());
|
|
|
|
|
|
+ // Delete item values
|
|
|
|
+ ExecuteWithSingleParam(db, "delete from ItemValues where ItemId=@Id", id.ToGuidParamValue());
|
|
|
|
|
|
- // Delete the item
|
|
|
|
- ExecuteWithSingleParam(db, "delete from TypedBaseItems where guid=@Id", id.ToGuidParamValue());
|
|
|
|
- });
|
|
|
|
|
|
+ // Delete the item
|
|
|
|
+ ExecuteWithSingleParam(db, "delete from TypedBaseItems where guid=@Id", id.ToGuidParamValue());
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -4417,19 +4463,22 @@ namespace Emby.Server.Implementations.Data
|
|
|
|
|
|
var list = new List<string>();
|
|
var list = new List<string>();
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection(true))
|
|
{
|
|
{
|
|
- using (var statement = _connection.PrepareStatement(commandText))
|
|
|
|
|
|
+ using (WriteLock.Read())
|
|
{
|
|
{
|
|
- // Run this again to bind the params
|
|
|
|
- GetPeopleWhereClauses(query, statement);
|
|
|
|
-
|
|
|
|
- foreach (var row in statement.ExecuteQuery())
|
|
|
|
|
|
+ using (var statement = connection.PrepareStatement(commandText))
|
|
{
|
|
{
|
|
- list.Add(row.GetString(0));
|
|
|
|
|
|
+ // Run this again to bind the params
|
|
|
|
+ GetPeopleWhereClauses(query, statement);
|
|
|
|
+
|
|
|
|
+ foreach (var row in statement.ExecuteQuery())
|
|
|
|
+ {
|
|
|
|
+ list.Add(row.GetString(0));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ return list;
|
|
}
|
|
}
|
|
- return list;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -4455,16 +4504,19 @@ namespace Emby.Server.Implementations.Data
|
|
|
|
|
|
var list = new List<PersonInfo>();
|
|
var list = new List<PersonInfo>();
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection(true))
|
|
{
|
|
{
|
|
- using (var statement = _connection.PrepareStatement(commandText))
|
|
|
|
|
|
+ using (WriteLock.Read())
|
|
{
|
|
{
|
|
- // Run this again to bind the params
|
|
|
|
- GetPeopleWhereClauses(query, statement);
|
|
|
|
-
|
|
|
|
- foreach (var row in statement.ExecuteQuery())
|
|
|
|
|
|
+ using (var statement = connection.PrepareStatement(commandText))
|
|
{
|
|
{
|
|
- list.Add(GetPerson(row));
|
|
|
|
|
|
+ // Run this again to bind the params
|
|
|
|
+ GetPeopleWhereClauses(query, statement);
|
|
|
|
+
|
|
|
|
+ foreach (var row in statement.ExecuteQuery())
|
|
|
|
+ {
|
|
|
|
+ list.Add(GetPerson(row));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -4667,13 +4719,16 @@ namespace Emby.Server.Implementations.Data
|
|
|
|
|
|
commandText += " Group By CleanValue";
|
|
commandText += " Group By CleanValue";
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection(true))
|
|
{
|
|
{
|
|
- foreach (var row in _connection.Query(commandText))
|
|
|
|
|
|
+ using (WriteLock.Write())
|
|
{
|
|
{
|
|
- if (!row.IsDBNull(0))
|
|
|
|
|
|
+ foreach (var row in connection.Query(commandText))
|
|
{
|
|
{
|
|
- list.Add(row.GetString(0));
|
|
|
|
|
|
+ if (!row.IsDBNull(0))
|
|
|
|
+ {
|
|
|
|
+ list.Add(row.GetString(0));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -4825,67 +4880,70 @@ namespace Emby.Server.Implementations.Data
|
|
var list = new List<Tuple<BaseItem, ItemCounts>>();
|
|
var list = new List<Tuple<BaseItem, ItemCounts>>();
|
|
var count = 0;
|
|
var count = 0;
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection(true, EnableJoinUserData(query)))
|
|
{
|
|
{
|
|
- if (!isReturningZeroItems)
|
|
|
|
|
|
+ using (WriteLock.Read())
|
|
{
|
|
{
|
|
- using (var statement = _connection.PrepareStatement(commandText))
|
|
|
|
|
|
+ if (!isReturningZeroItems)
|
|
{
|
|
{
|
|
- statement.TryBind("@SelectType", returnType);
|
|
|
|
- if (EnableJoinUserData(query))
|
|
|
|
|
|
+ using (var statement = connection.PrepareStatement(commandText))
|
|
{
|
|
{
|
|
- statement.TryBind("@UserId", query.User.Id);
|
|
|
|
- }
|
|
|
|
|
|
+ statement.TryBind("@SelectType", returnType);
|
|
|
|
+ if (EnableJoinUserData(query))
|
|
|
|
+ {
|
|
|
|
+ statement.TryBind("@UserId", query.User.Id);
|
|
|
|
+ }
|
|
|
|
|
|
- if (typeSubQuery != null)
|
|
|
|
- {
|
|
|
|
- GetWhereClauses(typeSubQuery, null, "itemTypes");
|
|
|
|
- }
|
|
|
|
- BindSimilarParams(query, statement);
|
|
|
|
- GetWhereClauses(innerQuery, statement);
|
|
|
|
- GetWhereClauses(outerQuery, statement);
|
|
|
|
|
|
+ if (typeSubQuery != null)
|
|
|
|
+ {
|
|
|
|
+ GetWhereClauses(typeSubQuery, null, "itemTypes");
|
|
|
|
+ }
|
|
|
|
+ BindSimilarParams(query, statement);
|
|
|
|
+ GetWhereClauses(innerQuery, statement);
|
|
|
|
+ GetWhereClauses(outerQuery, statement);
|
|
|
|
|
|
- foreach (var row in statement.ExecuteQuery())
|
|
|
|
- {
|
|
|
|
- var item = GetItem(row);
|
|
|
|
- if (item != null)
|
|
|
|
|
|
+ foreach (var row in statement.ExecuteQuery())
|
|
{
|
|
{
|
|
- var countStartColumn = columns.Count - 1;
|
|
|
|
|
|
+ var item = GetItem(row);
|
|
|
|
+ if (item != null)
|
|
|
|
+ {
|
|
|
|
+ var countStartColumn = columns.Count - 1;
|
|
|
|
|
|
- list.Add(new Tuple<BaseItem, ItemCounts>(item, GetItemCounts(row, countStartColumn, typesToCount)));
|
|
|
|
|
|
+ list.Add(new Tuple<BaseItem, ItemCounts>(item, GetItemCounts(row, countStartColumn, typesToCount)));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- LogQueryTime("GetItemValues", commandText, now);
|
|
|
|
|
|
+ LogQueryTime("GetItemValues", commandText, now);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- if (query.EnableTotalRecordCount)
|
|
|
|
- {
|
|
|
|
- commandText = "select count (distinct PresentationUniqueKey)" + GetFromText();
|
|
|
|
|
|
+ if (query.EnableTotalRecordCount)
|
|
|
|
+ {
|
|
|
|
+ commandText = "select count (distinct PresentationUniqueKey)" + GetFromText();
|
|
|
|
|
|
- commandText += GetJoinUserDataText(query);
|
|
|
|
- commandText += whereText;
|
|
|
|
|
|
+ commandText += GetJoinUserDataText(query);
|
|
|
|
+ commandText += whereText;
|
|
|
|
|
|
- using (var statement = _connection.PrepareStatement(commandText))
|
|
|
|
- {
|
|
|
|
- statement.TryBind("@SelectType", returnType);
|
|
|
|
- if (EnableJoinUserData(query))
|
|
|
|
|
|
+ using (var statement = connection.PrepareStatement(commandText))
|
|
{
|
|
{
|
|
- statement.TryBind("@UserId", query.User.Id);
|
|
|
|
- }
|
|
|
|
|
|
+ statement.TryBind("@SelectType", returnType);
|
|
|
|
+ if (EnableJoinUserData(query))
|
|
|
|
+ {
|
|
|
|
+ statement.TryBind("@UserId", query.User.Id);
|
|
|
|
+ }
|
|
|
|
|
|
- if (typeSubQuery != null)
|
|
|
|
- {
|
|
|
|
- GetWhereClauses(typeSubQuery, null, "itemTypes");
|
|
|
|
- }
|
|
|
|
- BindSimilarParams(query, statement);
|
|
|
|
- GetWhereClauses(innerQuery, statement);
|
|
|
|
- GetWhereClauses(outerQuery, statement);
|
|
|
|
|
|
+ if (typeSubQuery != null)
|
|
|
|
+ {
|
|
|
|
+ GetWhereClauses(typeSubQuery, null, "itemTypes");
|
|
|
|
+ }
|
|
|
|
+ BindSimilarParams(query, statement);
|
|
|
|
+ GetWhereClauses(innerQuery, statement);
|
|
|
|
+ GetWhereClauses(outerQuery, statement);
|
|
|
|
|
|
- count = statement.ExecuteQuery().SelectScalarInt().First();
|
|
|
|
|
|
+ count = statement.ExecuteQuery().SelectScalarInt().First();
|
|
|
|
|
|
- LogQueryTime("GetItemValues", commandText, now);
|
|
|
|
|
|
+ LogQueryTime("GetItemValues", commandText, now);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -5043,33 +5101,35 @@ namespace Emby.Server.Implementations.Data
|
|
|
|
|
|
CheckDisposed();
|
|
CheckDisposed();
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection())
|
|
{
|
|
{
|
|
- // First delete
|
|
|
|
- // "delete from People where ItemId=?"
|
|
|
|
- _connection.Execute("delete from People where ItemId=?", itemId.ToGuidParamValue());
|
|
|
|
|
|
+ using (WriteLock.Write())
|
|
|
|
+ { // First delete
|
|
|
|
+ // "delete from People where ItemId=?"
|
|
|
|
+ connection.Execute("delete from People where ItemId=?", itemId.ToGuidParamValue());
|
|
|
|
|
|
- var listIndex = 0;
|
|
|
|
|
|
+ var listIndex = 0;
|
|
|
|
|
|
- using (var statement = _connection.PrepareStatement(
|
|
|
|
- "insert into People (ItemId, Name, Role, PersonType, SortOrder, ListOrder) values (@ItemId, @Name, @Role, @PersonType, @SortOrder, @ListOrder)"))
|
|
|
|
- {
|
|
|
|
- foreach (var person in people)
|
|
|
|
|
|
+ using (var statement = connection.PrepareStatement(
|
|
|
|
+ "insert into People (ItemId, Name, Role, PersonType, SortOrder, ListOrder) values (@ItemId, @Name, @Role, @PersonType, @SortOrder, @ListOrder)"))
|
|
{
|
|
{
|
|
- if (listIndex > 0)
|
|
|
|
|
|
+ foreach (var person in people)
|
|
{
|
|
{
|
|
- statement.Reset();
|
|
|
|
- }
|
|
|
|
|
|
+ if (listIndex > 0)
|
|
|
|
+ {
|
|
|
|
+ statement.Reset();
|
|
|
|
+ }
|
|
|
|
|
|
- statement.TryBind("@ItemId", itemId.ToGuidParamValue());
|
|
|
|
- statement.TryBind("@Name", person.Name);
|
|
|
|
- statement.TryBind("@Role", person.Role);
|
|
|
|
- statement.TryBind("@PersonType", person.Type);
|
|
|
|
- statement.TryBind("@SortOrder", person.SortOrder);
|
|
|
|
- statement.TryBind("@ListOrder", listIndex);
|
|
|
|
|
|
+ statement.TryBind("@ItemId", itemId.ToGuidParamValue());
|
|
|
|
+ statement.TryBind("@Name", person.Name);
|
|
|
|
+ statement.TryBind("@Role", person.Role);
|
|
|
|
+ statement.TryBind("@PersonType", person.Type);
|
|
|
|
+ statement.TryBind("@SortOrder", person.SortOrder);
|
|
|
|
+ statement.TryBind("@ListOrder", listIndex);
|
|
|
|
|
|
- statement.MoveNext();
|
|
|
|
- listIndex++;
|
|
|
|
|
|
+ statement.MoveNext();
|
|
|
|
+ listIndex++;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -5127,25 +5187,28 @@ namespace Emby.Server.Implementations.Data
|
|
|
|
|
|
cmdText += " order by StreamIndex ASC";
|
|
cmdText += " order by StreamIndex ASC";
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection(true))
|
|
{
|
|
{
|
|
- using (var statement = _connection.PrepareStatement(cmdText))
|
|
|
|
|
|
+ using (WriteLock.Read())
|
|
{
|
|
{
|
|
- statement.TryBind("@ItemId", query.ItemId.ToGuidParamValue());
|
|
|
|
-
|
|
|
|
- if (query.Type.HasValue)
|
|
|
|
|
|
+ using (var statement = connection.PrepareStatement(cmdText))
|
|
{
|
|
{
|
|
- statement.TryBind("@StreamType", query.Type.Value.ToString());
|
|
|
|
- }
|
|
|
|
|
|
+ statement.TryBind("@ItemId", query.ItemId.ToGuidParamValue());
|
|
|
|
|
|
- if (query.Index.HasValue)
|
|
|
|
- {
|
|
|
|
- statement.TryBind("@StreamIndex", query.Index.Value);
|
|
|
|
- }
|
|
|
|
|
|
+ if (query.Type.HasValue)
|
|
|
|
+ {
|
|
|
|
+ statement.TryBind("@StreamType", query.Type.Value.ToString());
|
|
|
|
+ }
|
|
|
|
|
|
- foreach (var row in statement.ExecuteQuery())
|
|
|
|
- {
|
|
|
|
- list.Add(GetMediaStream(row));
|
|
|
|
|
|
+ if (query.Index.HasValue)
|
|
|
|
+ {
|
|
|
|
+ statement.TryBind("@StreamIndex", query.Index.Value);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ foreach (var row in statement.ExecuteQuery())
|
|
|
|
+ {
|
|
|
|
+ list.Add(GetMediaStream(row));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -5169,58 +5232,60 @@ namespace Emby.Server.Implementations.Data
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
- using (WriteLock.Write())
|
|
|
|
|
|
+ using (var connection = CreateConnection())
|
|
{
|
|
{
|
|
- // First delete chapters
|
|
|
|
- _connection.Execute("delete from mediastreams where ItemId=@ItemId", id.ToGuidParamValue());
|
|
|
|
|
|
+ using (WriteLock.Write())
|
|
|
|
+ { // First delete chapters
|
|
|
|
+ connection.Execute("delete from mediastreams where ItemId=@ItemId", id.ToGuidParamValue());
|
|
|
|
|
|
- using (var statement = _connection.PrepareStatement(string.Format("replace into mediastreams ({0}) values ({1})",
|
|
|
|
- string.Join(",", _mediaStreamSaveColumns),
|
|
|
|
- string.Join(",", _mediaStreamSaveColumns.Select(i => "@" + i).ToArray()))))
|
|
|
|
- {
|
|
|
|
- foreach (var stream in streams)
|
|
|
|
|
|
+ using (var statement = connection.PrepareStatement(string.Format("replace into mediastreams ({0}) values ({1})",
|
|
|
|
+ string.Join(",", _mediaStreamSaveColumns),
|
|
|
|
+ string.Join(",", _mediaStreamSaveColumns.Select(i => "@" + i).ToArray()))))
|
|
{
|
|
{
|
|
- var paramList = new List<object>();
|
|
|
|
-
|
|
|
|
- paramList.Add(id.ToGuidParamValue());
|
|
|
|
- paramList.Add(stream.Index);
|
|
|
|
- paramList.Add(stream.Type.ToString());
|
|
|
|
- paramList.Add(stream.Codec);
|
|
|
|
- paramList.Add(stream.Language);
|
|
|
|
- paramList.Add(stream.ChannelLayout);
|
|
|
|
- paramList.Add(stream.Profile);
|
|
|
|
- paramList.Add(stream.AspectRatio);
|
|
|
|
- paramList.Add(stream.Path);
|
|
|
|
-
|
|
|
|
- paramList.Add(stream.IsInterlaced);
|
|
|
|
- paramList.Add(stream.BitRate);
|
|
|
|
- paramList.Add(stream.Channels);
|
|
|
|
- paramList.Add(stream.SampleRate);
|
|
|
|
-
|
|
|
|
- paramList.Add(stream.IsDefault);
|
|
|
|
- paramList.Add(stream.IsForced);
|
|
|
|
- paramList.Add(stream.IsExternal);
|
|
|
|
-
|
|
|
|
- paramList.Add(stream.Width);
|
|
|
|
- paramList.Add(stream.Height);
|
|
|
|
- paramList.Add(stream.AverageFrameRate);
|
|
|
|
- paramList.Add(stream.RealFrameRate);
|
|
|
|
- paramList.Add(stream.Level);
|
|
|
|
- paramList.Add(stream.PixelFormat);
|
|
|
|
- paramList.Add(stream.BitDepth);
|
|
|
|
- paramList.Add(stream.IsExternal);
|
|
|
|
- paramList.Add(stream.RefFrames);
|
|
|
|
-
|
|
|
|
- paramList.Add(stream.CodecTag);
|
|
|
|
- paramList.Add(stream.Comment);
|
|
|
|
- paramList.Add(stream.NalLengthSize);
|
|
|
|
- paramList.Add(stream.IsAVC);
|
|
|
|
- paramList.Add(stream.Title);
|
|
|
|
-
|
|
|
|
- paramList.Add(stream.TimeBase);
|
|
|
|
- paramList.Add(stream.CodecTimeBase);
|
|
|
|
-
|
|
|
|
- statement.Execute(paramList.ToArray());
|
|
|
|
|
|
+ foreach (var stream in streams)
|
|
|
|
+ {
|
|
|
|
+ var paramList = new List<object>();
|
|
|
|
+
|
|
|
|
+ paramList.Add(id.ToGuidParamValue());
|
|
|
|
+ paramList.Add(stream.Index);
|
|
|
|
+ paramList.Add(stream.Type.ToString());
|
|
|
|
+ paramList.Add(stream.Codec);
|
|
|
|
+ paramList.Add(stream.Language);
|
|
|
|
+ paramList.Add(stream.ChannelLayout);
|
|
|
|
+ paramList.Add(stream.Profile);
|
|
|
|
+ paramList.Add(stream.AspectRatio);
|
|
|
|
+ paramList.Add(stream.Path);
|
|
|
|
+
|
|
|
|
+ paramList.Add(stream.IsInterlaced);
|
|
|
|
+ paramList.Add(stream.BitRate);
|
|
|
|
+ paramList.Add(stream.Channels);
|
|
|
|
+ paramList.Add(stream.SampleRate);
|
|
|
|
+
|
|
|
|
+ paramList.Add(stream.IsDefault);
|
|
|
|
+ paramList.Add(stream.IsForced);
|
|
|
|
+ paramList.Add(stream.IsExternal);
|
|
|
|
+
|
|
|
|
+ paramList.Add(stream.Width);
|
|
|
|
+ paramList.Add(stream.Height);
|
|
|
|
+ paramList.Add(stream.AverageFrameRate);
|
|
|
|
+ paramList.Add(stream.RealFrameRate);
|
|
|
|
+ paramList.Add(stream.Level);
|
|
|
|
+ paramList.Add(stream.PixelFormat);
|
|
|
|
+ paramList.Add(stream.BitDepth);
|
|
|
|
+ paramList.Add(stream.IsExternal);
|
|
|
|
+ paramList.Add(stream.RefFrames);
|
|
|
|
+
|
|
|
|
+ paramList.Add(stream.CodecTag);
|
|
|
|
+ paramList.Add(stream.Comment);
|
|
|
|
+ paramList.Add(stream.NalLengthSize);
|
|
|
|
+ paramList.Add(stream.IsAVC);
|
|
|
|
+ paramList.Add(stream.Title);
|
|
|
|
+
|
|
|
|
+ paramList.Add(stream.TimeBase);
|
|
|
|
+ paramList.Add(stream.CodecTimeBase);
|
|
|
|
+
|
|
|
|
+ statement.Execute(paramList.ToArray());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|