update clean db task

This commit is contained in:
Luke Pulverenti 2016-02-02 21:51:00 -05:00
parent 4e6d3dba5b
commit e602577401

View File

@ -65,17 +65,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
innerProgress.RegisterAction(p => innerProgress.RegisterAction(p =>
{ {
double newPercentCommplete = .4 * p; double newPercentCommplete = .4 * p;
if (EnableUnavailableMessage) OnProgress(newPercentCommplete);
{
var html = "<!doctype html><html><head><title>Emby</title></head><body>";
var text = _localization.GetLocalizedString("DbUpgradeMessage");
html += string.Format(text, newPercentCommplete.ToString("N2", CultureInfo.InvariantCulture));
html += "<script>setTimeout(function(){window.location.reload(true);}, 5000);</script>";
html += "</body></html>";
_httpServer.GlobalResponse = html;
}
progress.Report(newPercentCommplete); progress.Report(newPercentCommplete);
}); });
@ -83,12 +73,22 @@ namespace MediaBrowser.Server.Implementations.Persistence
await UpdateToLatestSchema(cancellationToken, innerProgress).ConfigureAwait(false); await UpdateToLatestSchema(cancellationToken, innerProgress).ConfigureAwait(false);
innerProgress = new ActionableProgress<double>(); innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(p => progress.Report(40 + (.05 * p))); innerProgress.RegisterAction(p =>
{
double newPercentCommplete = 40 + (.05 * p);
OnProgress(newPercentCommplete);
progress.Report(newPercentCommplete);
});
await CleanDeadItems(cancellationToken, innerProgress).ConfigureAwait(false); await CleanDeadItems(cancellationToken, innerProgress).ConfigureAwait(false);
progress.Report(45); progress.Report(45);
innerProgress = new ActionableProgress<double>(); innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(p => progress.Report(45 + (.55 * p))); innerProgress.RegisterAction(p =>
{
double newPercentCommplete = 45 + (.55 * p);
OnProgress(newPercentCommplete);
progress.Report(newPercentCommplete);
});
await CleanDeletedItems(cancellationToken, innerProgress).ConfigureAwait(false); await CleanDeletedItems(cancellationToken, innerProgress).ConfigureAwait(false);
progress.Report(100); progress.Report(100);
@ -101,6 +101,21 @@ namespace MediaBrowser.Server.Implementations.Persistence
} }
} }
private void OnProgress(double newPercentCommplete)
{
if (EnableUnavailableMessage)
{
var html = "<!doctype html><html><head><title>Emby</title></head><body>";
var text = _localization.GetLocalizedString("DbUpgradeMessage");
html += string.Format(text, newPercentCommplete.ToString("N2", CultureInfo.InvariantCulture));
html += "<script>setTimeout(function(){window.location.reload(true);}, 5000);</script>";
html += "</body></html>";
_httpServer.GlobalResponse = html;
}
}
private async Task UpdateToLatestSchema(CancellationToken cancellationToken, IProgress<double> progress) private async Task UpdateToLatestSchema(CancellationToken cancellationToken, IProgress<double> progress)
{ {
var itemIds = _libraryManager.GetItemIds(new InternalItemsQuery var itemIds = _libraryManager.GetItemIds(new InternalItemsQuery
@ -117,27 +132,25 @@ namespace MediaBrowser.Server.Implementations.Persistence
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
if (itemId == Guid.Empty) if (itemId != Guid.Empty)
{ {
// Somehow some invalid data got into the db. It probably predates the boundary checking // Somehow some invalid data got into the db. It probably predates the boundary checking
continue; var item = _libraryManager.GetItemById(itemId);
}
var item = _libraryManager.GetItemById(itemId); if (item != null)
if (item != null)
{
try
{ {
await _itemRepo.SaveItem(item, cancellationToken).ConfigureAwait(false); try
} {
catch (OperationCanceledException) await _itemRepo.SaveItem(item, cancellationToken).ConfigureAwait(false);
{ }
throw; catch (OperationCanceledException)
} {
catch (Exception ex) throw;
{ }
_logger.ErrorException("Error saving item", ex); catch (Exception ex)
{
_logger.ErrorException("Error saving item", ex);
}
} }
} }