Browse Source

remove plex items from index after sign out (#94)

pull/96/head
Jason Dove 5 years ago committed by GitHub
parent
commit
00fdc272e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      ErsatzTV.Application/Plex/Commands/SignOutOfPlexHandler.cs
  2. 2
      ErsatzTV.Core/Interfaces/Repositories/IMediaSourceRepository.cs
  3. 8
      ErsatzTV.Infrastructure/Data/Repositories/MediaSourceRepository.cs

12
ErsatzTV.Application/Plex/Commands/SignOutOfPlexHandler.cs

@ -1,9 +1,11 @@
using System.Threading; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using ErsatzTV.Core; using ErsatzTV.Core;
using ErsatzTV.Core.Interfaces.Locking; using ErsatzTV.Core.Interfaces.Locking;
using ErsatzTV.Core.Interfaces.Plex; using ErsatzTV.Core.Interfaces.Plex;
using ErsatzTV.Core.Interfaces.Repositories; using ErsatzTV.Core.Interfaces.Repositories;
using ErsatzTV.Core.Interfaces.Search;
using LanguageExt; using LanguageExt;
namespace ErsatzTV.Application.Plex.Commands namespace ErsatzTV.Application.Plex.Commands
@ -13,20 +15,24 @@ namespace ErsatzTV.Application.Plex.Commands
private readonly IEntityLocker _entityLocker; private readonly IEntityLocker _entityLocker;
private readonly IMediaSourceRepository _mediaSourceRepository; private readonly IMediaSourceRepository _mediaSourceRepository;
private readonly IPlexSecretStore _plexSecretStore; private readonly IPlexSecretStore _plexSecretStore;
private readonly ISearchIndex _searchIndex;
public SignOutOfPlexHandler( public SignOutOfPlexHandler(
IMediaSourceRepository mediaSourceRepository, IMediaSourceRepository mediaSourceRepository,
IPlexSecretStore plexSecretStore, IPlexSecretStore plexSecretStore,
IEntityLocker entityLocker) IEntityLocker entityLocker,
ISearchIndex searchIndex)
{ {
_mediaSourceRepository = mediaSourceRepository; _mediaSourceRepository = mediaSourceRepository;
_plexSecretStore = plexSecretStore; _plexSecretStore = plexSecretStore;
_entityLocker = entityLocker; _entityLocker = entityLocker;
_searchIndex = searchIndex;
} }
public async Task<Either<BaseError, Unit>> Handle(SignOutOfPlex request, CancellationToken cancellationToken) public async Task<Either<BaseError, Unit>> Handle(SignOutOfPlex request, CancellationToken cancellationToken)
{ {
await _mediaSourceRepository.DeleteAllPlex(); List<int> ids = await _mediaSourceRepository.DeleteAllPlex();
await _searchIndex.RemoveItems(ids);
await _plexSecretStore.DeleteAll(); await _plexSecretStore.DeleteAll();
_entityLocker.UnlockPlex(); _entityLocker.UnlockPlex();

2
ErsatzTV.Core/Interfaces/Repositories/IMediaSourceRepository.cs

@ -35,7 +35,7 @@ namespace ErsatzTV.Core.Interfaces.Repositories
Task Update(PlexLibrary plexMediaSourceLibrary); Task Update(PlexLibrary plexMediaSourceLibrary);
Task Delete(int mediaSourceId); Task Delete(int mediaSourceId);
Task<Unit> DeleteAllPlex(); Task<List<int>> DeleteAllPlex();
Task<List<int>> DisablePlexLibrarySync(List<int> libraryIds); Task<List<int>> DisablePlexLibrarySync(List<int> libraryIds);
Task EnablePlexLibrarySync(IEnumerable<int> libraryIds); Task EnablePlexLibrarySync(IEnumerable<int> libraryIds);
} }

8
ErsatzTV.Infrastructure/Data/Repositories/MediaSourceRepository.cs

@ -257,7 +257,7 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
await context.SaveChangesAsync(); await context.SaveChangesAsync();
} }
public async Task<Unit> DeleteAllPlex() public async Task<List<int>> DeleteAllPlex()
{ {
await using TvContext context = _dbContextFactory.CreateDbContext(); await using TvContext context = _dbContextFactory.CreateDbContext();
@ -267,8 +267,12 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
List<PlexLibrary> allPlexLibraries = await context.PlexLibraries.ToListAsync(); List<PlexLibrary> allPlexLibraries = await context.PlexLibraries.ToListAsync();
context.PlexLibraries.RemoveRange(allPlexLibraries); context.PlexLibraries.RemoveRange(allPlexLibraries);
List<int> movieIds = await context.PlexMovies.Map(pm => pm.Id).ToListAsync();
List<int> showIds = await context.PlexShows.Map(ps => ps.Id).ToListAsync();
await context.SaveChangesAsync(); await context.SaveChangesAsync();
return Unit.Default;
return movieIds.Append(showIds).ToList();
} }
public async Task<List<int>> DisablePlexLibrarySync(List<int> libraryIds) public async Task<List<int>> DisablePlexLibrarySync(List<int> libraryIds)

Loading…
Cancel
Save