From d350dc0edbff437cc2e5775e386da167dbd1224e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 23 Dec 2016 12:09:50 -0500 Subject: resolve error saving sync jobs --- Emby.Server.Implementations/Sync/SyncRepository.cs | 91 ++++++++++++++-------- 1 file changed, 60 insertions(+), 31 deletions(-) (limited to 'Emby.Server.Implementations/Sync/SyncRepository.cs') diff --git a/Emby.Server.Implementations/Sync/SyncRepository.cs b/Emby.Server.Implementations/Sync/SyncRepository.cs index 885f8e64a..6d4fce399 100644 --- a/Emby.Server.Implementations/Sync/SyncRepository.cs +++ b/Emby.Server.Implementations/Sync/SyncRepository.cs @@ -221,48 +221,77 @@ namespace Emby.Server.Implementations.Sync using (var connection = CreateConnection()) { string commandText; - var paramList = new List(); if (insert) { - commandText = "insert into SyncJobs (Id, TargetId, Name, Profile, Quality, Bitrate, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + commandText = "insert into SyncJobs (Id, TargetId, Name, Profile, Quality, Bitrate, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount) values (@Id, @TargetId, @Name, @Profile, @Quality, @Bitrate, @Status, @Progress, @UserId, @ItemIds, @Category, @ParentId, @UnwatchedOnly, @ItemLimit, @SyncNewContent, @DateCreated, @DateLastModified, @ItemCount)"; } else { - commandText = "update SyncJobs set TargetId=?,Name=?,Profile=?,Quality=?,Bitrate=?,Status=?,Progress=?,UserId=?,ItemIds=?,Category=?,ParentId=?,UnwatchedOnly=?,ItemLimit=?,SyncNewContent=?,DateCreated=?,DateLastModified=?,ItemCount=? where Id=?"; + commandText = "update SyncJobs set TargetId=@TargetId,Name=@Name,Profile=@Profile,Quality=@Quality,Bitrate=@Bitrate,Status=@Status,Progress=@Progress,UserId=@UserId,ItemIds=@ItemIds,Category=@Category,ParentId=@ParentId,UnwatchedOnly=@UnwatchedOnly,ItemLimit=@ItemLimit,SyncNewContent=@SyncNewContent,DateCreated=@DateCreated,DateLastModified=@DateLastModified,ItemCount=@ItemCount where Id=@Id"; } - paramList.Add(job.TargetId); - paramList.Add(job.Name); - paramList.Add(job.Profile); - paramList.Add(job.Quality); - paramList.Add(job.Bitrate); - paramList.Add(job.Status.ToString()); - paramList.Add(job.Progress); - paramList.Add(job.UserId); + connection.RunInTransaction(conn => + { + using (var statement = PrepareStatementSafe(connection, commandText)) + { + statement.TryBind("@TargetId", job.TargetId); + statement.TryBind("@Name", job.Name); + statement.TryBind("@Profile", job.Profile); + statement.TryBind("@Quality", job.Quality); + statement.TryBind("@Bitrate", job.Bitrate); + statement.TryBind("@Status", job.Status.ToString()); + statement.TryBind("@Progress", job.Progress); + statement.TryBind("@UserId", job.UserId); + + if (job.RequestedItemIds.Count > 0) + { + statement.TryBind("@ItemIds", string.Join(",", job.RequestedItemIds.ToArray())); + } + else + { + statement.TryBindNull("@ItemIds"); + } - paramList.Add(string.Join(",", job.RequestedItemIds.ToArray())); - paramList.Add(job.Category); - paramList.Add(job.ParentId); - paramList.Add(job.UnwatchedOnly); - paramList.Add(job.ItemLimit); - paramList.Add(job.SyncNewContent); - paramList.Add(job.DateCreated.ToDateTimeParamValue()); - paramList.Add(job.DateLastModified.ToDateTimeParamValue()); - paramList.Add(job.ItemCount); + if (job.Category.HasValue) + { + statement.TryBind("@Category", job.Category.Value.ToString()); + } + else + { + statement.TryBindNull("@Category"); + } - if (insert) - { - paramList.Insert(0, job.Id.ToGuidParamValue()); - } - else - { - paramList.Add(job.Id.ToGuidParamValue()); - } + if (!string.IsNullOrWhiteSpace(job.ParentId)) + { + statement.TryBind("@ParentId", job.ParentId); + } + else + { + statement.TryBindNull("@ParentId"); + } - connection.RunInTransaction(conn => - { - conn.Execute(commandText, paramList.ToArray()); + statement.TryBind("@UnwatchedOnly", job.UnwatchedOnly); + + if (job.ItemLimit.HasValue) + { + statement.TryBind("@ItemLimit", job.ItemLimit); + } + else + { + statement.TryBindNull("@ItemLimit"); + } + + statement.TryBind("@SyncNewContent", job.SyncNewContent); + + statement.TryBind("@DateCreated", job.DateCreated.ToDateTimeParamValue()); + statement.TryBind("@DateLastModified", job.DateLastModified.ToDateTimeParamValue()); + + statement.TryBind("@ItemCount", job.ItemCount); + statement.TryBind("@Id", job.Id.ToGuidParamValue()); + + statement.MoveNext(); + } }, TransactionMode); } } -- cgit v1.2.3 From a1acc0c1619bcb4d7e6720edb1e9d5775eb23713 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 27 Dec 2016 14:34:27 -0500 Subject: resolve sync failure --- Emby.Server.Implementations/Sync/SyncRepository.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'Emby.Server.Implementations/Sync/SyncRepository.cs') diff --git a/Emby.Server.Implementations/Sync/SyncRepository.cs b/Emby.Server.Implementations/Sync/SyncRepository.cs index 6d4fce399..ad4222ba6 100644 --- a/Emby.Server.Implementations/Sync/SyncRepository.cs +++ b/Emby.Server.Implementations/Sync/SyncRepository.cs @@ -244,14 +244,7 @@ namespace Emby.Server.Implementations.Sync statement.TryBind("@Progress", job.Progress); statement.TryBind("@UserId", job.UserId); - if (job.RequestedItemIds.Count > 0) - { - statement.TryBind("@ItemIds", string.Join(",", job.RequestedItemIds.ToArray())); - } - else - { - statement.TryBindNull("@ItemIds"); - } + statement.TryBind("@ItemIds", string.Join(",", job.RequestedItemIds.ToArray())); if (job.Category.HasValue) { -- cgit v1.2.3 From 28bbe32d1dc50ce7ad199f50acb5b2b4791b1b4c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 28 Dec 2016 03:16:21 -0500 Subject: update sync cancellation --- Emby.Server.Implementations/Sync/SyncManager.cs | 12 ++++++++++++ Emby.Server.Implementations/Sync/SyncRepository.cs | 5 +++++ MediaBrowser.Model/Sync/SyncJobQuery.cs | 1 + 3 files changed, 18 insertions(+) (limited to 'Emby.Server.Implementations/Sync/SyncRepository.cs') diff --git a/Emby.Server.Implementations/Sync/SyncManager.cs b/Emby.Server.Implementations/Sync/SyncManager.cs index 061129e5f..d3b6b33a2 100644 --- a/Emby.Server.Implementations/Sync/SyncManager.cs +++ b/Emby.Server.Implementations/Sync/SyncManager.cs @@ -1030,6 +1030,18 @@ namespace Emby.Server.Implementations.Sync { await CancelJobItem(jobItem.Id).ConfigureAwait(false); } + + var syncJobResult = await GetJobs(new SyncJobQuery + { + ItemId = item, + TargetId = targetId + + }).ConfigureAwait(false); + + foreach (var job in syncJobResult.Items) + { + await CancelJob(job.Id).ConfigureAwait(false); + } } } diff --git a/Emby.Server.Implementations/Sync/SyncRepository.cs b/Emby.Server.Implementations/Sync/SyncRepository.cs index ad4222ba6..aafce3500 100644 --- a/Emby.Server.Implementations/Sync/SyncRepository.cs +++ b/Emby.Server.Implementations/Sync/SyncRepository.cs @@ -360,6 +360,11 @@ namespace Emby.Server.Implementations.Sync whereClauses.Add("UserId=?"); paramList.Add(query.UserId); } + if (!string.IsNullOrWhiteSpace(query.ItemId)) + { + whereClauses.Add("ItemIds like ?"); + paramList.Add("%" + query.ItemId + "%"); + } if (query.SyncNewContent.HasValue) { whereClauses.Add("SyncNewContent=?"); diff --git a/MediaBrowser.Model/Sync/SyncJobQuery.cs b/MediaBrowser.Model/Sync/SyncJobQuery.cs index bb99b5d5f..ed9e5ae60 100644 --- a/MediaBrowser.Model/Sync/SyncJobQuery.cs +++ b/MediaBrowser.Model/Sync/SyncJobQuery.cs @@ -24,6 +24,7 @@ namespace MediaBrowser.Model.Sync /// The user identifier. public string UserId { get; set; } public string ExcludeTargetIds { get; set; } + public string ItemId { get; set; } /// /// Gets or sets the status. /// -- cgit v1.2.3