rework emby collection scanning (#1205)
* optimize emby collection scan frequency * add button to sync emby collections * update changelog * fix scanning; add progress indicator
This commit is contained in:
@@ -59,6 +59,9 @@ public class ScannerService : BackgroundService
|
||||
case ISynchronizeEmbyLibraryById synchronizeEmbyLibraryById:
|
||||
requestTask = SynchronizeEmbyLibrary(synchronizeEmbyLibraryById, cancellationToken);
|
||||
break;
|
||||
case SynchronizeEmbyCollections synchronizeEmbyCollections:
|
||||
requestTask = SynchronizeEmbyCollections(synchronizeEmbyCollections, cancellationToken);
|
||||
break;
|
||||
case IScanLocalLibrary scanLocalLibrary:
|
||||
requestTask = SynchronizeLocalLibrary(scanLocalLibrary, cancellationToken);
|
||||
break;
|
||||
@@ -274,5 +277,34 @@ public class ScannerService : BackgroundService
|
||||
entityLocker.UnlockLibrary(request.EmbyLibraryId);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SynchronizeEmbyCollections(
|
||||
SynchronizeEmbyCollections request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
using IServiceScope scope = _serviceScopeFactory.CreateScope();
|
||||
IMediator mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
|
||||
IEntityLocker entityLocker = scope.ServiceProvider.GetRequiredService<IEntityLocker>();
|
||||
|
||||
Either<BaseError, Unit> result = await mediator.Send(request, cancellationToken);
|
||||
result.BiIter(
|
||||
_ => _logger.LogDebug("Done synchronizing emby collections"),
|
||||
error =>
|
||||
{
|
||||
if (error is ScanIsNotRequired)
|
||||
{
|
||||
_logger.LogDebug("Scan is not required for emby collections at this time");
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Unable to synchronize emby collections: {Error}", error.Value);
|
||||
}
|
||||
});
|
||||
|
||||
if (entityLocker.AreEmbyCollectionsLocked())
|
||||
{
|
||||
entityLocker.UnlockEmbyCollections();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -236,8 +236,12 @@ public class SchedulerService : BackgroundService
|
||||
using IServiceScope scope = _serviceScopeFactory.CreateScope();
|
||||
TvContext dbContext = scope.ServiceProvider.GetRequiredService<TvContext>();
|
||||
|
||||
var mediaSourceIds = new System.Collections.Generic.HashSet<int>();
|
||||
|
||||
foreach (EmbyLibrary library in dbContext.EmbyLibraries.Filter(l => l.ShouldSyncItems))
|
||||
{
|
||||
mediaSourceIds.Add(library.MediaSourceId);
|
||||
|
||||
if (_entityLocker.LockLibrary(library.Id))
|
||||
{
|
||||
await _scannerWorkerChannel.WriteAsync(
|
||||
@@ -245,6 +249,13 @@ public class SchedulerService : BackgroundService
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (int mediaSourceId in mediaSourceIds)
|
||||
{
|
||||
await _scannerWorkerChannel.WriteAsync(
|
||||
new SynchronizeEmbyCollections(mediaSourceId, false),
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task MatchTraktLists(CancellationToken cancellationToken)
|
||||
|
||||
Reference in New Issue
Block a user