Always await instead of directly returning Task

https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/blob/master/AsyncGuidance.md#prefer-asyncawait-over-directly-returning-task

The performance impact is negligible (and it's me saying that!)
This commit is contained in:
Bond_009
2024-10-31 17:02:06 +01:00
parent 282784cbb6
commit d2db700402
14 changed files with 60 additions and 91 deletions

View File

@@ -148,21 +148,19 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
item.Overview = (overview ?? string.Empty).StripHtml();
}
internal Task EnsureInfo(string musicBrainzReleaseGroupId, CancellationToken cancellationToken)
internal async Task EnsureInfo(string musicBrainzReleaseGroupId, CancellationToken cancellationToken)
{
var xmlPath = GetAlbumInfoPath(_config.ApplicationPaths, musicBrainzReleaseGroupId);
var fileInfo = _fileSystem.GetFileSystemInfo(xmlPath);
if (fileInfo.Exists)
if (fileInfo.Exists
&& (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 2)
{
if ((DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 2)
{
return Task.CompletedTask;
}
return;
}
return DownloadInfo(musicBrainzReleaseGroupId, cancellationToken);
await DownloadInfo(musicBrainzReleaseGroupId, cancellationToken).ConfigureAwait(false);
}
internal async Task DownloadInfo(string musicBrainzReleaseGroupId, CancellationToken cancellationToken)

View File

@@ -131,7 +131,7 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
item.Overview = (overview ?? string.Empty).StripHtml();
}
internal Task EnsureArtistInfo(string musicBrainzId, CancellationToken cancellationToken)
internal async Task EnsureArtistInfo(string musicBrainzId, CancellationToken cancellationToken)
{
var xmlPath = GetArtistInfoPath(_config.ApplicationPaths, musicBrainzId);
@@ -140,10 +140,10 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
if (fileInfo.Exists
&& (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 2)
{
return Task.CompletedTask;
return;
}
return DownloadArtistInfo(musicBrainzId, cancellationToken);
await DownloadArtistInfo(musicBrainzId, cancellationToken).ConfigureAwait(false);
}
internal async Task DownloadArtistInfo(string musicBrainzId, CancellationToken cancellationToken)

View File

@@ -101,11 +101,11 @@ namespace MediaBrowser.Providers.Plugins.StudioImages
return string.Format(CultureInfo.InvariantCulture, "{0}/images/{1}/{2}.jpg", GetRepositoryUrl(), image, filename);
}
private Task EnsureThumbsList(string file, CancellationToken cancellationToken)
private async Task EnsureThumbsList(string file, CancellationToken cancellationToken)
{
string url = string.Format(CultureInfo.InvariantCulture, "{0}/thumbs.txt", GetRepositoryUrl());
return EnsureList(url, file, _fileSystem, cancellationToken);
await EnsureList(url, file, _fileSystem, cancellationToken).ConfigureAwait(false);
}
/// <inheritdoc />