use cancellation tokens in many places (#2350)
* use cancellation tokens everywhere * more cancellation tokens
This commit is contained in:
@@ -531,19 +531,25 @@ public class MetadataRepository : IMetadataRepository
|
||||
.Map(result => result > 0);
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateSubtitles(Core.Domain.Metadata metadata, List<Subtitle> subtitles)
|
||||
public async Task<bool> UpdateSubtitles(
|
||||
Core.Domain.Metadata metadata,
|
||||
List<Subtitle> subtitles,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
return await UpdateSubtitles(dbContext, metadata, subtitles);
|
||||
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||
return await UpdateSubtitles(dbContext, metadata, subtitles, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateChapters(MediaVersion version, List<MediaChapter> chapters)
|
||||
public async Task<bool> UpdateChapters(
|
||||
MediaVersion version,
|
||||
List<MediaChapter> chapters,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||
|
||||
Option<MediaVersion> maybeExisting = await dbContext.MediaVersions
|
||||
.Include(mv => mv.Chapters)
|
||||
.SelectOneAsync(mv => mv.Id, mv => mv.Id == version.Id);
|
||||
.SelectOneAsync(mv => mv.Id, mv => mv.Id == version.Id, cancellationToken);
|
||||
|
||||
foreach (MediaVersion existing in maybeExisting)
|
||||
{
|
||||
@@ -572,7 +578,7 @@ public class MetadataRepository : IMetadataRepository
|
||||
existingChapter.Title = incomingChapter.Title;
|
||||
}
|
||||
|
||||
return await dbContext.SaveChangesAsync() > 0;
|
||||
return await dbContext.SaveChangesAsync(cancellationToken) > 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -624,7 +630,8 @@ public class MetadataRepository : IMetadataRepository
|
||||
private static async Task<bool> UpdateSubtitles(
|
||||
TvContext dbContext,
|
||||
Core.Domain.Metadata metadata,
|
||||
List<Subtitle> subtitles)
|
||||
List<Subtitle> subtitles,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
// _logger.LogDebug(
|
||||
// "Updating {Count} subtitles; metadata is {Metadata}",
|
||||
@@ -637,19 +644,19 @@ public class MetadataRepository : IMetadataRepository
|
||||
{
|
||||
EpisodeMetadata => await dbContext.EpisodeMetadata
|
||||
.Include(em => em.Subtitles)
|
||||
.SelectOneAsync(em => em.Id, em => em.Id == metadataId)
|
||||
.SelectOneAsync(em => em.Id, em => em.Id == metadataId, cancellationToken)
|
||||
.MapT(em => (Core.Domain.Metadata)em),
|
||||
MovieMetadata => await dbContext.MovieMetadata
|
||||
.Include(mm => mm.Subtitles)
|
||||
.SelectOneAsync(mm => mm.Id, mm => mm.Id == metadataId)
|
||||
.SelectOneAsync(mm => mm.Id, mm => mm.Id == metadataId, cancellationToken)
|
||||
.MapT(mm => (Core.Domain.Metadata)mm),
|
||||
MusicVideoMetadata => await dbContext.MusicVideoMetadata
|
||||
.Include(mvm => mvm.Subtitles)
|
||||
.SelectOneAsync(mvm => mvm.Id, mm => mm.Id == metadataId)
|
||||
.SelectOneAsync(mvm => mvm.Id, mm => mm.Id == metadataId, cancellationToken)
|
||||
.MapT(mvm => (Core.Domain.Metadata)mvm),
|
||||
OtherVideoMetadata => await dbContext.OtherVideoMetadata
|
||||
.Include(ovm => ovm.Subtitles)
|
||||
.SelectOneAsync(ovm => ovm.Id, mm => mm.Id == metadataId)
|
||||
.SelectOneAsync(ovm => ovm.Id, mm => mm.Id == metadataId, cancellationToken)
|
||||
.MapT(ovm => (Core.Domain.Metadata)ovm),
|
||||
_ => None
|
||||
};
|
||||
@@ -697,7 +704,7 @@ public class MetadataRepository : IMetadataRepository
|
||||
dbContext.Entry(existingSubtitle).State = EntityState.Modified;
|
||||
}
|
||||
|
||||
int count = await dbContext.SaveChangesAsync();
|
||||
int count = await dbContext.SaveChangesAsync(cancellationToken);
|
||||
|
||||
// _logger.LogDebug("Subtitles update changed {Count} records in the db", count);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user