aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua M. Boniface <joshua@boniface.me>2019-02-27 00:31:48 -0500
committerGitHub <noreply@github.com>2019-02-27 00:31:48 -0500
commitaea7edf0fa182397b8eba8936b7ed092a88f916c (patch)
tree61a10fc2a453733c4effa1c799c0d1ebafb071c3
parent42d4834f63699b25554695f9d196fa1441d48226 (diff)
parent0fbc4545d1b9f8b3e5af3324d92ab0c0ef0fafe2 (diff)
Merge pull request #891 from Bond-009/postsan
Reduce the amount of db calls during the post scan event
-rw-r--r--Emby.Server.Implementations/Channels/ChannelPostScanTask.cs48
1 files changed, 18 insertions, 30 deletions
diff --git a/Emby.Server.Implementations/Channels/ChannelPostScanTask.cs b/Emby.Server.Implementations/Channels/ChannelPostScanTask.cs
index ad6c537ef..3c7cbb115 100644
--- a/Emby.Server.Implementations/Channels/ChannelPostScanTask.cs
+++ b/Emby.Server.Implementations/Channels/ChannelPostScanTask.cs
@@ -35,64 +35,52 @@ namespace Emby.Server.Implementations.Channels
public static string GetUserDistinctValue(User user)
{
var channels = user.Policy.EnabledChannels
- .OrderBy(i => i)
- .ToList();
+ .OrderBy(i => i);
- return string.Join("|", channels.ToArray());
+ return string.Join("|", channels);
}
private void CleanDatabase(CancellationToken cancellationToken)
{
var installedChannelIds = ((ChannelManager)_channelManager).GetInstalledChannelIds();
- var databaseIds = _libraryManager.GetItemIds(new InternalItemsQuery
+ var uninstalledChannels = _libraryManager.GetItemList(new InternalItemsQuery
{
- IncludeItemTypes = new[] { typeof(Channel).Name }
+ IncludeItemTypes = new[] { typeof(Channel).Name },
+ ExcludeItemIds = installedChannelIds.ToArray()
});
- var invalidIds = databaseIds
- .Except(installedChannelIds)
- .ToList();
-
- foreach (var id in invalidIds)
+ foreach (var channel in uninstalledChannels)
{
cancellationToken.ThrowIfCancellationRequested();
- CleanChannel(id, cancellationToken);
+ CleanChannel((Channel)channel, cancellationToken);
}
}
- private void CleanChannel(Guid id, CancellationToken cancellationToken)
+ private void CleanChannel(Channel channel, CancellationToken cancellationToken)
{
- _logger.LogInformation("Cleaning channel {0} from database", id);
+ _logger.LogInformation("Cleaning channel {0} from database", channel.Id);
// Delete all channel items
- var allIds = _libraryManager.GetItemIds(new InternalItemsQuery
+ var items = _libraryManager.GetItemList(new InternalItemsQuery
{
- ChannelIds = new[] { id }
+ ChannelIds = new[] { channel.Id }
});
- foreach (var deleteId in allIds)
+ foreach (var item in items)
{
cancellationToken.ThrowIfCancellationRequested();
- DeleteItem(deleteId);
- }
-
- // Finally, delete the channel itself
- DeleteItem(id);
- }
+ _libraryManager.DeleteItem(item, new DeleteOptions
+ {
+ DeleteFileLocation = false
- private void DeleteItem(Guid id)
- {
- var item = _libraryManager.GetItemById(id);
-
- if (item == null)
- {
- return;
+ }, false);
}
- _libraryManager.DeleteItem(item, new DeleteOptions
+ // Finally, delete the channel itself
+ _libraryManager.DeleteItem(channel, new DeleteOptions
{
DeleteFileLocation = false