delete orphan plex media sources (#85)

* delete orphan plex media sources

* fix plex db warning on startup
This commit is contained in:
Jason Dove
2021-03-19 01:14:18 +00:00
committed by GitHub
parent 739d074bc6
commit 493a496b91
4 changed files with 1713 additions and 6 deletions
@@ -107,14 +107,19 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
.Map(Optional);
}
public Task<Option<PlexMediaSource>> GetPlexByLibraryId(int plexLibraryId)
public async Task<Option<PlexMediaSource>> GetPlexByLibraryId(int plexLibraryId)
{
using TvContext context = _dbContextFactory.CreateDbContext();
return context.PlexMediaSources
int? id = await _dbConnection.QuerySingleAsync<int?>(
@"SELECT L.MediaSourceId FROM Library L
INNER JOIN PlexLibrary PL on L.Id = PL.Id
WHERE L.Id = @PlexLibraryId", new { PlexLibraryId = plexLibraryId });
await using TvContext context = _dbContextFactory.CreateDbContext();
return await context.PlexMediaSources
.Include(p => p.Connections)
.Include(p => p.Libraries)
.Where(p => p.Libraries.Any(l => l.Id == plexLibraryId))
.SingleOrDefaultAsync()
.OrderBy(p => p.Id)
.SingleOrDefaultAsync(p => p.Id == id)
.Map(Optional);
}