update server sync

pull/702/head
Luke Pulverenti 10 years ago
parent af90f0a059
commit 401c962c7f

@ -42,8 +42,9 @@ namespace MediaBrowser.Controller.Sync
/// Gets the cached item.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="id">The identifier.</param>
/// <param name="serverId">The server identifier.</param>
/// <param name="itemId">The item identifier.</param>
/// <returns>Task&lt;LocalItem&gt;.</returns>
Task<LocalItem> GetCachedItem(SyncTarget target, string id);
Task<List<LocalItem>> GetCachedItems(SyncTarget target, string serverId, string itemId);
}
}

@ -143,7 +143,7 @@ namespace MediaBrowser.Server.Implementations.Sync
var fileTransferProgress = new ActionableProgress<double>();
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,14 +188,10 @@ 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);
foreach (var file in files)
@ -203,7 +199,8 @@ namespace MediaBrowser.Server.Implementations.Sync
await provider.DeleteFile(file.Path, target, cancellationToken).ConfigureAwait(false);
}
await dataProvider.Delete(target, localId).ConfigureAwait(false);
await dataProvider.Delete(target, localItem.Id).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)
};
}

@ -40,6 +40,8 @@ namespace MediaBrowser.Server.Implementations.Sync
.SelectMany(i => i.GetAllSyncTargets().Select(t => new Tuple<IServerSyncProvider, SyncTarget>(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));
}
}
}

@ -232,11 +232,12 @@ namespace MediaBrowser.Server.Implementations.Sync
.ToList();
}
public async Task<LocalItem> GetCachedItem(SyncTarget target, string id)
public async Task<List<LocalItem>> 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();
}
}
}

Loading…
Cancel
Save