keep channels db clean
This commit is contained in:
parent
03e6cfde60
commit
fafa879eef
|
@ -18,12 +18,14 @@ namespace MediaBrowser.Server.Implementations.Channels
|
|||
private readonly IChannelManager _channelManager;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
|
||||
public ChannelPostScanTask(IChannelManager channelManager, IUserManager userManager, ILogger logger)
|
||||
public ChannelPostScanTask(IChannelManager channelManager, IUserManager userManager, ILogger logger, ILibraryManager libraryManager)
|
||||
{
|
||||
_channelManager = channelManager;
|
||||
_userManager = userManager;
|
||||
_logger = logger;
|
||||
_libraryManager = libraryManager;
|
||||
}
|
||||
|
||||
public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
|
@ -52,6 +54,8 @@ namespace MediaBrowser.Server.Implementations.Channels
|
|||
progress.Report(percent * 100);
|
||||
}
|
||||
|
||||
await CleanDatabase(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
progress.Report(100);
|
||||
}
|
||||
|
||||
|
@ -63,7 +67,7 @@ namespace MediaBrowser.Server.Implementations.Channels
|
|||
|
||||
return string.Join("|", channels.ToArray());
|
||||
}
|
||||
|
||||
|
||||
private async Task DownloadContent(string user, CancellationToken cancellationToken, IProgress<double> progress)
|
||||
{
|
||||
var channels = await _channelManager.GetChannelsInternal(new ChannelQuery
|
||||
|
@ -116,6 +120,59 @@ namespace MediaBrowser.Server.Implementations.Channels
|
|||
progress.Report(100);
|
||||
}
|
||||
|
||||
private async Task CleanDatabase(CancellationToken cancellationToken)
|
||||
{
|
||||
var allChannels = await _channelManager.GetChannelsInternal(new ChannelQuery { }, cancellationToken);
|
||||
|
||||
var allIds = _libraryManager.GetItemIds(new InternalItemsQuery
|
||||
{
|
||||
IncludeItemTypes = new[] { typeof(Channel).Name }
|
||||
});
|
||||
|
||||
var invalidIds = allIds
|
||||
.Except(allChannels.Items.Select(i => i.Id).ToList())
|
||||
.ToList();
|
||||
|
||||
foreach (var id in invalidIds)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
await CleanChannel(id, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CleanChannel(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.Debug("Cleaning channel {0} from database", id);
|
||||
|
||||
// Delete all channel items
|
||||
var allIds = _libraryManager.GetItemIds(new InternalItemsQuery
|
||||
{
|
||||
ChannelIds = new[] { id.ToString("N") }
|
||||
});
|
||||
|
||||
foreach (var deleteId in allIds)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
await DeleteItem(deleteId).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// Finally, delete the channel itself
|
||||
await DeleteItem(id).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private Task DeleteItem(Guid id)
|
||||
{
|
||||
var item = _libraryManager.GetItemById(id);
|
||||
|
||||
return _libraryManager.DeleteItem(item, new DeleteOptions
|
||||
{
|
||||
DeleteFileLocation = false
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private async Task GetAllItems(string user, string channelId, string folderId, int currentRefreshLevel, int maxRefreshLevel, IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
var folderItems = new List<string>();
|
||||
|
|
|
@ -13,12 +13,14 @@ namespace MediaBrowser.Server.Implementations.Channels
|
|||
private readonly IChannelManager _channelManager;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
|
||||
public RefreshChannelsScheduledTask(IChannelManager channelManager, IUserManager userManager, ILogger logger)
|
||||
public RefreshChannelsScheduledTask(IChannelManager channelManager, IUserManager userManager, ILogger logger, ILibraryManager libraryManager)
|
||||
{
|
||||
_channelManager = channelManager;
|
||||
_userManager = userManager;
|
||||
_logger = logger;
|
||||
_libraryManager = libraryManager;
|
||||
}
|
||||
|
||||
public string Name
|
||||
|
@ -42,7 +44,7 @@ namespace MediaBrowser.Server.Implementations.Channels
|
|||
|
||||
await manager.RefreshChannels(new Progress<double>(), cancellationToken).ConfigureAwait(false);
|
||||
|
||||
await new ChannelPostScanTask(_channelManager, _userManager, _logger).Run(progress, cancellationToken)
|
||||
await new ChannelPostScanTask(_channelManager, _userManager, _logger, _libraryManager).Run(progress, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -84,6 +84,8 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
|||
|
||||
foreach (var id in invalidIds)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var item = _libraryManager.GetItemById(id);
|
||||
|
||||
await _libraryManager.DeleteItem(item, new DeleteOptions
|
||||
|
|
|
@ -85,6 +85,8 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
|||
|
||||
foreach (var id in invalidIds)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var item = _libraryManager.GetItemById(id);
|
||||
|
||||
await _libraryManager.DeleteItem(item, new DeleteOptions
|
||||
|
|
|
@ -85,6 +85,8 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
|||
|
||||
foreach (var id in invalidIds)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var item = _libraryManager.GetItemById(id);
|
||||
|
||||
await _libraryManager.DeleteItem(item, new DeleteOptions
|
||||
|
|
|
@ -92,15 +92,25 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
|||
|
||||
foreach (var person in people)
|
||||
{
|
||||
bool current;
|
||||
if (!dict.TryGetValue(person.Name, out current) || !current)
|
||||
var isMetadataEnabled = DownloadMetadata(person, peopleOptions);
|
||||
|
||||
bool currentValue;
|
||||
if (dict.TryGetValue(person.Name, out currentValue))
|
||||
{
|
||||
dict[person.Name] = DownloadMetadata(person, peopleOptions);
|
||||
if (!currentValue && isMetadataEnabled)
|
||||
{
|
||||
dict[person.Name] = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dict[person.Name] = isMetadataEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
var numComplete = 0;
|
||||
|
||||
var validIds = new List<Guid>();
|
||||
|
||||
foreach (var person in dict)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
@ -109,6 +119,8 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
|||
{
|
||||
var item = _libraryManager.GetPerson(person.Key);
|
||||
|
||||
validIds.Add(item.Id);
|
||||
|
||||
var options = new MetadataRefreshOptions
|
||||
{
|
||||
MetadataRefreshMode = person.Value ? MetadataRefreshMode.Default : MetadataRefreshMode.ValidationOnly,
|
||||
|
@ -130,6 +142,28 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
|||
progress.Report(100 * percent);
|
||||
}
|
||||
|
||||
var allIds = _libraryManager.GetItemIds(new InternalItemsQuery
|
||||
{
|
||||
IncludeItemTypes = new[] { typeof(Person).Name }
|
||||
});
|
||||
|
||||
var invalidIds = allIds
|
||||
.Except(validIds)
|
||||
.ToList();
|
||||
|
||||
foreach (var id in invalidIds)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var item = _libraryManager.GetItemById(id);
|
||||
|
||||
await _libraryManager.DeleteItem(item, new DeleteOptions
|
||||
{
|
||||
DeleteFileLocation = false
|
||||
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
progress.Report(100);
|
||||
|
||||
_logger.Info("People validation complete");
|
||||
|
|
|
@ -84,6 +84,8 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
|||
|
||||
foreach (var id in invalidIds)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var item = _libraryManager.GetItemById(id);
|
||||
|
||||
await _libraryManager.DeleteItem(item, new DeleteOptions
|
||||
|
|
|
@ -21,7 +21,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
|
||||
{
|
||||
public class EmbyTV : ILiveTvService, IHasRegistrationInfo, IDisposable
|
||||
public class EmbyTV : ILiveTvService/*, IHasRegistrationInfo*/, IDisposable
|
||||
{
|
||||
private readonly IApplicationHost _appHpst;
|
||||
private readonly ILogger _logger;
|
||||
|
|
Loading…
Reference in New Issue
Block a user