diff --git a/MediaBrowser.Controller/Sync/ISyncDataProvider.cs b/MediaBrowser.Controller/Sync/ISyncDataProvider.cs
index 5a86b74d80..f84748b971 100644
--- a/MediaBrowser.Controller/Sync/ISyncDataProvider.cs
+++ b/MediaBrowser.Controller/Sync/ISyncDataProvider.cs
@@ -42,8 +42,9 @@ namespace MediaBrowser.Controller.Sync
/// Gets the cached item.
///
/// The target.
- /// The identifier.
+ /// The server identifier.
+ /// The item identifier.
/// Task<LocalItem>.
- Task GetCachedItem(SyncTarget target, string id);
+ Task> GetCachedItems(SyncTarget target, string serverId, string itemId);
}
}
diff --git a/MediaBrowser.Server.Implementations/Sync/MediaSync.cs b/MediaBrowser.Server.Implementations/Sync/MediaSync.cs
index ff298a9998..8391dbd7a2 100644
--- a/MediaBrowser.Server.Implementations/Sync/MediaSync.cs
+++ b/MediaBrowser.Server.Implementations/Sync/MediaSync.cs
@@ -143,7 +143,7 @@ namespace MediaBrowser.Server.Implementations.Sync
var fileTransferProgress = new ActionableProgress();
fileTransferProgress.RegisterAction(pct => progress.Report(pct * .92));
- var localItem = CreateLocalItem(provider, jobItem.SyncJobId, target, libraryItem, serverId, jobItem.OriginalFileName);
+ var localItem = CreateLocalItem(provider, jobItem.SyncJobId, jobItem.SyncJobItemId, target, libraryItem, serverId, jobItem.OriginalFileName);
await _syncManager.ReportSyncJobItemTransferBeginning(internalSyncJobItem.Id);
@@ -188,22 +188,19 @@ namespace MediaBrowser.Server.Implementations.Sync
SyncTarget target,
CancellationToken cancellationToken)
{
- var localId = GetLocalId(serverId, itemId);
- var localItem = await dataProvider.Get(target, localId);
+ var localItems = await dataProvider.GetCachedItems(target, serverId, itemId);
- if (localItem == null)
+ foreach (var localItem in localItems)
{
- return;
- }
+ var files = await GetFiles(provider, localItem, target);
- var files = await GetFiles(provider, localItem, target);
+ foreach (var file in files)
+ {
+ await provider.DeleteFile(file.Path, target, cancellationToken).ConfigureAwait(false);
+ }
- foreach (var file in files)
- {
- await provider.DeleteFile(file.Path, target, cancellationToken).ConfigureAwait(false);
+ await dataProvider.Delete(target, localItem.Id).ConfigureAwait(false);
}
-
- await dataProvider.Delete(target, localId).ConfigureAwait(false);
}
private async Task SendFile(IServerSyncProvider provider, string inputPath, LocalItem item, SyncTarget target, CancellationToken cancellationToken)
@@ -214,9 +211,9 @@ namespace MediaBrowser.Server.Implementations.Sync
}
}
- internal static string GetLocalId(string serverId, string itemId)
+ private static string GetLocalId(string jobItemId, string itemId)
{
- var bytes = Encoding.UTF8.GetBytes(serverId + itemId);
+ var bytes = Encoding.UTF8.GetBytes(jobItemId + itemId);
bytes = CreateMd5(bytes);
return BitConverter.ToString(bytes, 0, bytes.Length).Replace("-", string.Empty);
}
@@ -229,7 +226,7 @@ namespace MediaBrowser.Server.Implementations.Sync
}
}
- public LocalItem CreateLocalItem(IServerSyncProvider provider, string syncJobId, SyncTarget target, BaseItemDto libraryItem, string serverId, string originalFileName)
+ public LocalItem CreateLocalItem(IServerSyncProvider provider, string syncJobId, string syncJobItemId, SyncTarget target, BaseItemDto libraryItem, string serverId, string originalFileName)
{
var path = GetDirectoryPath(provider, syncJobId, libraryItem, serverId);
path.Add(GetLocalFileName(provider, libraryItem, originalFileName));
@@ -248,7 +245,7 @@ namespace MediaBrowser.Server.Implementations.Sync
ItemId = libraryItem.Id,
ServerId = serverId,
LocalPath = localPath,
- Id = GetLocalId(serverId, libraryItem.Id)
+ Id = GetLocalId(syncJobItemId, libraryItem.Id)
};
}
diff --git a/MediaBrowser.Server.Implementations/Sync/SyncedMediaSourceProvider.cs b/MediaBrowser.Server.Implementations/Sync/SyncedMediaSourceProvider.cs
index 91e7a25370..3e0df94f5a 100644
--- a/MediaBrowser.Server.Implementations/Sync/SyncedMediaSourceProvider.cs
+++ b/MediaBrowser.Server.Implementations/Sync/SyncedMediaSourceProvider.cs
@@ -40,6 +40,8 @@ namespace MediaBrowser.Server.Implementations.Sync
.SelectMany(i => i.GetAllSyncTargets().Select(t => new Tuple(i, t)))
.ToList();
+ var serverId = _appHost.SystemId;
+
foreach (var jobItem in jobItemResult.Items)
{
var targetTuple = targets.FirstOrDefault(i => string.Equals(i.Item2.Id, jobItem.TargetId, StringComparison.OrdinalIgnoreCase));
@@ -49,14 +51,10 @@ namespace MediaBrowser.Server.Implementations.Sync
var syncTarget = targetTuple.Item2;
var dataProvider = _syncManager.GetDataProvider(targetTuple.Item1, syncTarget);
- var localItemId = MediaSync.GetLocalId(_appHost.SystemId, item.Id.ToString("N"));
- var localItem = await dataProvider.GetCachedItem(syncTarget, localItemId).ConfigureAwait(false);
+ var localItems = await dataProvider.GetCachedItems(syncTarget, serverId, item.Id.ToString("N")).ConfigureAwait(false);
- if (localItem != null)
- {
- list.AddRange(localItem.Item.MediaSources);
- }
+ list.AddRange(localItems.SelectMany(i => i.Item.MediaSources));
}
}
}
diff --git a/MediaBrowser.Server.Implementations/Sync/TargetDataProvider.cs b/MediaBrowser.Server.Implementations/Sync/TargetDataProvider.cs
index d068a9e4a7..ca9d96c12f 100644
--- a/MediaBrowser.Server.Implementations/Sync/TargetDataProvider.cs
+++ b/MediaBrowser.Server.Implementations/Sync/TargetDataProvider.cs
@@ -232,11 +232,12 @@ namespace MediaBrowser.Server.Implementations.Sync
.ToList();
}
- public async Task GetCachedItem(SyncTarget target, string id)
+ public async Task> GetCachedItems(SyncTarget target, string serverId, string itemId)
{
var items = await GetCachedData().ConfigureAwait(false);
- return items.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.OrdinalIgnoreCase));
+ return items.Where(i => string.Equals(i.ServerId, serverId, StringComparison.OrdinalIgnoreCase) && string.Equals(i.ItemId, itemId, StringComparison.OrdinalIgnoreCase))
+ .ToList();
}
}
}