mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-04-24 14:08:44 -04:00
Reduce the amount of db calls during the post scan event
This commit is contained in:
parent
a2dd2ddd55
commit
bca569da42
1 changed files with 18 additions and 30 deletions
|
@ -35,64 +35,52 @@ namespace Emby.Server.Implementations.Channels
|
||||||
public static string GetUserDistinctValue(User user)
|
public static string GetUserDistinctValue(User user)
|
||||||
{
|
{
|
||||||
var channels = user.Policy.EnabledChannels
|
var channels = user.Policy.EnabledChannels
|
||||||
.OrderBy(i => i)
|
.OrderBy(i => i);
|
||||||
.ToList();
|
|
||||||
|
|
||||||
return string.Join("|", channels.ToArray());
|
return string.Join("|", channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CleanDatabase(CancellationToken cancellationToken)
|
private void CleanDatabase(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var installedChannelIds = ((ChannelManager)_channelManager).GetInstalledChannelIds();
|
var installedChannelIds = ((ChannelManager)_channelManager).GetInstalledChannelIds();
|
||||||
|
|
||||||
var databaseIds = _libraryManager.GetItemIds(new InternalItemsQuery
|
var databaseIds = _libraryManager.GetItemList(new InternalItemsQuery
|
||||||
{
|
{
|
||||||
IncludeItemTypes = new[] { typeof(Channel).Name }
|
IncludeItemTypes = new[] { typeof(Channel).Name },
|
||||||
|
ExcludeItemIds = installedChannelIds.ToArray()
|
||||||
});
|
});
|
||||||
|
|
||||||
var invalidIds = databaseIds
|
foreach (var channel in databaseIds.Cast<Channel>())
|
||||||
.Except(installedChannelIds)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
foreach (var id in invalidIds)
|
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
CleanChannel(id, cancellationToken);
|
CleanChannel(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
|
// 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();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
DeleteItem(deleteId);
|
_libraryManager.DeleteItem(item, new DeleteOptions
|
||||||
|
{
|
||||||
|
DeleteFileLocation = false
|
||||||
|
|
||||||
|
}, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, delete the channel itself
|
// Finally, delete the channel itself
|
||||||
DeleteItem(id);
|
_libraryManager.DeleteItem(channel, new DeleteOptions
|
||||||
}
|
|
||||||
|
|
||||||
private void DeleteItem(Guid id)
|
|
||||||
{
|
|
||||||
var item = _libraryManager.GetItemById(id);
|
|
||||||
|
|
||||||
if (item == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_libraryManager.DeleteItem(item, new DeleteOptions
|
|
||||||
{
|
{
|
||||||
DeleteFileLocation = false
|
DeleteFileLocation = false
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue