Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix long live tv load times, Fixes #10761 #10881

Merged
merged 4 commits into from
Feb 1, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions Emby.Server.Implementations/Library/LiveStreamHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,29 @@ public async Task AddMediaInfoWithProbe(MediaSourceInfo mediaSource, bool isAudi

if (!string.IsNullOrEmpty(cacheKey))
{
FileStream jsonStream = AsyncFile.OpenRead(cacheFilePath);
try
{
mediaInfo = await JsonSerializer.DeserializeAsync<MediaInfo>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
FileStream jsonStream = AsyncFile.OpenRead(cacheFilePath);

// _logger.LogDebug("Found cached media info");
try
{
mediaInfo = await JsonSerializer.DeserializeAsync<MediaInfo>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
// _logger.LogDebug("Found cached media info");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean the commented logDebug? If so it was there before so I left it there.

}
catch (Exception ex)
{
_logger.LogError(ex, "Error deserializing mediainfo cache");
}

await jsonStream.DisposeAsync().ConfigureAwait(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
try
{
mediaInfo = await JsonSerializer.DeserializeAsync<MediaInfo>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
// _logger.LogDebug("Found cached media info");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error deserializing mediainfo cache");
}
await jsonStream.DisposeAsync().ConfigureAwait(false);
await using (jsonStream.ConfigureAwait(false))
{
mediaInfo = await JsonSerializer.DeserializeAsync<MediaInfo>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
// _logger.LogDebug("Found cached media info");
}

IMO converting the nested try-catch into a using statement makes more sense. I believe the new disposable analyzer would flag this, so we'd need to do it eventually anyways

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, just wasn't sure if the DisposeAsync line was needed but i assume the using will dispose of it even if this fails. This does look much nicer than nested try catch. Ive updated PR.

}
catch (Exception ex)
catch (IOException ex)
{
_logger.LogError(ex, "Error deserializing mediainfo cache");
_logger.LogDebug(ex, "Could not open cached media info");
}
finally
catch (Exception ex)
{
await jsonStream.DisposeAsync().ConfigureAwait(false);
_logger.LogError(ex, "Error opening cached media info");
}
}

Expand Down
Loading