fixes #1261 - Sync quality cannot be changed

This commit is contained in:
Luke Pulverenti 2016-04-16 01:05:34 -04:00
parent 81d9ea05f6
commit bfc8facc60
3 changed files with 23 additions and 32 deletions

View File

@ -149,16 +149,6 @@ namespace MediaBrowser.Server.Implementations.Sync
{ {
var job = _syncRepo.GetJob(id); var job = _syncRepo.GetJob(id);
return UpdateJobStatus(job);
}
private Task UpdateJobStatus(SyncJob job)
{
if (job == null)
{
throw new ArgumentNullException("job");
}
var result = _syncManager.GetJobItems(new SyncJobItemQuery var result = _syncManager.GetJobItems(new SyncJobItemQuery
{ {
JobId = job.Id, JobId = job.Id,
@ -476,14 +466,12 @@ namespace MediaBrowser.Server.Implementations.Sync
if (jobItem != null) if (jobItem != null)
{ {
var job = _syncRepo.GetJob(jobItem.JobId);
if (jobItem.Status != SyncJobItemStatus.Cancelled) if (jobItem.Status != SyncJobItemStatus.Cancelled)
{ {
await ProcessJobItem(job, jobItem, enableConversion, innerProgress, cancellationToken).ConfigureAwait(false); await ProcessJobItem(jobItem, enableConversion, innerProgress, cancellationToken).ConfigureAwait(false);
} }
job = _syncRepo.GetJob(jobItem.JobId); await UpdateJobStatus(jobItem.JobId).ConfigureAwait(false);
await UpdateJobStatus(job).ConfigureAwait(false);
} }
numComplete++; numComplete++;
@ -493,7 +481,7 @@ namespace MediaBrowser.Server.Implementations.Sync
} }
} }
private async Task ProcessJobItem(SyncJob job, SyncJobItem jobItem, bool enableConversion, IProgress<double> progress, CancellationToken cancellationToken) private async Task ProcessJobItem(SyncJobItem jobItem, bool enableConversion, IProgress<double> progress, CancellationToken cancellationToken)
{ {
var item = _libraryManager.GetItemById(jobItem.ItemId); var item = _libraryManager.GetItemById(jobItem.ItemId);
if (item == null) if (item == null)
@ -507,6 +495,7 @@ namespace MediaBrowser.Server.Implementations.Sync
jobItem.Progress = 0; jobItem.Progress = 0;
var syncOptions = _config.GetSyncOptions(); var syncOptions = _config.GetSyncOptions();
var job = _syncManager.GetJob(jobItem.JobId);
var user = _userManager.GetUserById(job.UserId); var user = _userManager.GetUserById(job.UserId);
if (user == null) if (user == null)
{ {
@ -521,7 +510,7 @@ namespace MediaBrowser.Server.Implementations.Sync
{ {
AddMetadata = false, AddMetadata = false,
ItemId = jobItem.ItemId, ItemId = jobItem.ItemId,
TargetId = job.TargetId, TargetId = jobItem.TargetId,
Statuses = new[] { SyncJobItemStatus.Converting, SyncJobItemStatus.Queued, SyncJobItemStatus.ReadyToTransfer, SyncJobItemStatus.Synced, SyncJobItemStatus.Transferring } Statuses = new[] { SyncJobItemStatus.Converting, SyncJobItemStatus.Queued, SyncJobItemStatus.ReadyToTransfer, SyncJobItemStatus.Synced, SyncJobItemStatus.Transferring }
}); });
@ -531,7 +520,7 @@ namespace MediaBrowser.Server.Implementations.Sync
if (duplicateJobItems.Count > 0) if (duplicateJobItems.Count > 0)
{ {
var syncProvider = _syncManager.GetSyncProvider(jobItem, job) as IHasDuplicateCheck; var syncProvider = _syncManager.GetSyncProvider(jobItem) as IHasDuplicateCheck;
if (!duplicateJobItems.Any(i => AllowDuplicateJobItem(syncProvider, i, jobItem))) if (!duplicateJobItems.Any(i => AllowDuplicateJobItem(syncProvider, i, jobItem)))
{ {
@ -545,12 +534,12 @@ namespace MediaBrowser.Server.Implementations.Sync
var video = item as Video; var video = item as Video;
if (video != null) if (video != null)
{ {
await Sync(jobItem, job, video, user, enableConversion, syncOptions, progress, cancellationToken).ConfigureAwait(false); await Sync(jobItem, video, user, enableConversion, syncOptions, progress, cancellationToken).ConfigureAwait(false);
} }
else if (item is Audio) else if (item is Audio)
{ {
await Sync(jobItem, job, (Audio)item, user, enableConversion, syncOptions, progress, cancellationToken).ConfigureAwait(false); await Sync(jobItem, (Audio)item, user, enableConversion, syncOptions, progress, cancellationToken).ConfigureAwait(false);
} }
else if (item is Photo) else if (item is Photo)
@ -574,8 +563,9 @@ namespace MediaBrowser.Server.Implementations.Sync
return true; return true;
} }
private async Task Sync(SyncJobItem jobItem, SyncJob job, Video item, User user, bool enableConversion, SyncOptions syncOptions, IProgress<double> progress, CancellationToken cancellationToken) private async Task Sync(SyncJobItem jobItem, Video item, User user, bool enableConversion, SyncOptions syncOptions, IProgress<double> progress, CancellationToken cancellationToken)
{ {
var job = _syncManager.GetJob(jobItem.JobId);
var jobOptions = _syncManager.GetVideoOptions(jobItem, job); var jobOptions = _syncManager.GetVideoOptions(jobItem, job);
var conversionOptions = new VideoOptions var conversionOptions = new VideoOptions
{ {
@ -616,7 +606,7 @@ namespace MediaBrowser.Server.Implementations.Sync
{ {
// Save the job item now since conversion could take a while // Save the job item now since conversion could take a while
await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false);
await UpdateJobStatus(job).ConfigureAwait(false); await UpdateJobStatus(jobItem.JobId).ConfigureAwait(false);
try try
{ {
@ -630,7 +620,7 @@ namespace MediaBrowser.Server.Implementations.Sync
{ {
jobItem.Progress = pct / 2; jobItem.Progress = pct / 2;
await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false);
await UpdateJobStatus(job).ConfigureAwait(false); await UpdateJobStatus(jobItem.JobId).ConfigureAwait(false);
} }
}); });
@ -642,7 +632,7 @@ namespace MediaBrowser.Server.Implementations.Sync
}, innerProgress, cancellationToken); }, innerProgress, cancellationToken);
_syncManager.OnConversionComplete(jobItem, job); _syncManager.OnConversionComplete(jobItem);
} }
catch (OperationCanceledException) catch (OperationCanceledException)
{ {
@ -775,8 +765,9 @@ namespace MediaBrowser.Server.Implementations.Sync
private const int DatabaseProgressUpdateIntervalSeconds = 2; private const int DatabaseProgressUpdateIntervalSeconds = 2;
private async Task Sync(SyncJobItem jobItem, SyncJob job, Audio item, User user, bool enableConversion, SyncOptions syncOptions, IProgress<double> progress, CancellationToken cancellationToken) private async Task Sync(SyncJobItem jobItem, Audio item, User user, bool enableConversion, SyncOptions syncOptions, IProgress<double> progress, CancellationToken cancellationToken)
{ {
var job = _syncManager.GetJob(jobItem.JobId);
var jobOptions = _syncManager.GetAudioOptions(jobItem, job); var jobOptions = _syncManager.GetAudioOptions(jobItem, job);
var conversionOptions = new AudioOptions var conversionOptions = new AudioOptions
{ {
@ -803,7 +794,7 @@ namespace MediaBrowser.Server.Implementations.Sync
jobItem.Status = SyncJobItemStatus.Converting; jobItem.Status = SyncJobItemStatus.Converting;
await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false);
await UpdateJobStatus(job).ConfigureAwait(false); await UpdateJobStatus(jobItem.JobId).ConfigureAwait(false);
try try
{ {
@ -817,7 +808,7 @@ namespace MediaBrowser.Server.Implementations.Sync
{ {
jobItem.Progress = pct / 2; jobItem.Progress = pct / 2;
await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false);
await UpdateJobStatus(job).ConfigureAwait(false); await UpdateJobStatus(jobItem.JobId).ConfigureAwait(false);
} }
}); });
@ -828,7 +819,7 @@ namespace MediaBrowser.Server.Implementations.Sync
}, innerProgress, cancellationToken); }, innerProgress, cancellationToken);
_syncManager.OnConversionComplete(jobItem, job); _syncManager.OnConversionComplete(jobItem);
} }
catch (OperationCanceledException) catch (OperationCanceledException)
{ {

View File

@ -1117,7 +1117,7 @@ namespace MediaBrowser.Server.Implementations.Sync
public SyncJobOptions GetAudioOptions(SyncJobItem jobItem, SyncJob job) public SyncJobOptions GetAudioOptions(SyncJobItem jobItem, SyncJob job)
{ {
var options = GetSyncJobOptions(jobItem.TargetId, null, null); var options = GetSyncJobOptions(jobItem.TargetId, null, null);
if (job.Bitrate.HasValue) if (job.Bitrate.HasValue)
{ {
options.DeviceProfile.MaxStaticBitrate = job.Bitrate.Value; options.DeviceProfile.MaxStaticBitrate = job.Bitrate.Value;
@ -1126,7 +1126,7 @@ namespace MediaBrowser.Server.Implementations.Sync
return options; return options;
} }
public ISyncProvider GetSyncProvider(SyncJobItem jobItem, SyncJob job) public ISyncProvider GetSyncProvider(SyncJobItem jobItem)
{ {
foreach (var provider in _providers) foreach (var provider in _providers)
{ {
@ -1323,9 +1323,9 @@ namespace MediaBrowser.Server.Implementations.Sync
return list; return list;
} }
protected internal void OnConversionComplete(SyncJobItem item, SyncJob job) protected internal void OnConversionComplete(SyncJobItem item)
{ {
var syncProvider = GetSyncProvider(item, job); var syncProvider = GetSyncProvider(item);
if (syncProvider is AppSyncProvider) if (syncProvider is AppSyncProvider)
{ {
return; return;

View File

@ -104,7 +104,7 @@ namespace MediaBrowser.Server.Implementations.Sync
// _updateJobCommand // _updateJobCommand
_updateJobCommand = _connection.CreateCommand(); _updateJobCommand = _connection.CreateCommand();
_updateJobCommand.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"; _updateJobCommand.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";
_updateJobCommand.Parameters.Add(_updateJobCommand, "@Id"); _updateJobCommand.Parameters.Add(_updateJobCommand, "@Id");
_updateJobCommand.Parameters.Add(_updateJobCommand, "@TargetId"); _updateJobCommand.Parameters.Add(_updateJobCommand, "@TargetId");