Skip to content

Commit

Permalink
fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
crobibero committed Mar 26, 2024
1 parent 09514f5 commit a820449
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
38 changes: 25 additions & 13 deletions Jellyfin.Plugin.Tvdb/TvdbClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class TvdbClientManager : IDisposable

private readonly IHttpClientFactory _httpClientFactory;
private readonly IServiceProvider _serviceProvider;
private readonly IMemoryCache _memoryCache;
private readonly MemoryCache _memoryCache;
private readonly SdkClientSettings _sdkClientSettings;

private DateTime _tokenUpdatedAt;
Expand Down Expand Up @@ -113,7 +113,8 @@ public async Task<IReadOnlyList<SearchResult>> GetSeriesByNameAsync(
CancellationToken cancellationToken)
{
var key = $"TvdbSeriesSearch_{name}";
if (_memoryCache.TryGetValue(key, out IReadOnlyList<SearchResult> series))
if (_memoryCache.TryGetValue(key, out IReadOnlyList<SearchResult>? series)
&& series is not null)
{
return series;
}
Expand All @@ -139,7 +140,8 @@ public async Task<SeriesBaseRecord> GetSeriesByIdAsync(
CancellationToken cancellationToken)
{
var key = $"TvdbSeries_{tvdbId.ToString(CultureInfo.InvariantCulture)}";
if (_memoryCache.TryGetValue(key, out SeriesBaseRecord series))
if (_memoryCache.TryGetValue(key, out SeriesBaseRecord? series)
&& series is not null)
{
return series;
}
Expand Down Expand Up @@ -169,7 +171,8 @@ public async Task<SeriesExtendedRecord> GetSeriesExtendedByIdAsync(
bool? small = null)
{
var key = $"TvdbSeriesExtended_{tvdbId.ToString(CultureInfo.InvariantCulture)}_{meta}_{small}";
if (_memoryCache.TryGetValue(key, out SeriesExtendedRecord series))
if (_memoryCache.TryGetValue(key, out SeriesExtendedRecord? series)
&& series is not null)
{
return series;
}
Expand Down Expand Up @@ -197,7 +200,8 @@ public async Task<Data2> GetSeriesEpisodesAsync(
CancellationToken cancellationToken)
{
var key = $"TvdbSeriesEpisodes_{tvdbId.ToString(CultureInfo.InvariantCulture)}_{seasonType}";
if (_memoryCache.TryGetValue(key, out Data2 series))
if (_memoryCache.TryGetValue(key, out Data2? series)
&& series is not null)
{
return series;
}
Expand All @@ -223,7 +227,8 @@ public async Task<SeasonExtendedRecord> GetSeasonByIdAsync(
CancellationToken cancellationToken)
{
var key = $"TvdbSeason_{seasonTvdbId.ToString(CultureInfo.InvariantCulture)}";
if (_memoryCache.TryGetValue(key, out SeasonExtendedRecord season))
if (_memoryCache.TryGetValue(key, out SeasonExtendedRecord? season)
&& season is not null)
{
return season;
}
Expand All @@ -249,7 +254,8 @@ public async Task<EpisodeExtendedRecord> GetEpisodesAsync(
CancellationToken cancellationToken)
{
var key = $"TvdbEpisode_{episodeTvdbId.ToString(CultureInfo.InvariantCulture)}";
if (_memoryCache.TryGetValue(key, out EpisodeExtendedRecord episode))
if (_memoryCache.TryGetValue(key, out EpisodeExtendedRecord? episode)
&& episode is not null)
{
return episode;
}
Expand All @@ -275,7 +281,8 @@ public async Task<IReadOnlyList<SearchByRemoteIdResult>> GetSeriesByRemoteIdAsyn
CancellationToken cancellationToken)
{
var key = $"TvdbSeriesRemoteId_{remoteId}";
if (_memoryCache.TryGetValue(key, out IReadOnlyList<SearchByRemoteIdResult> series))
if (_memoryCache.TryGetValue(key, out IReadOnlyList<SearchByRemoteIdResult>? series)
&& series is not null)
{
return series;
}
Expand All @@ -301,7 +308,8 @@ public async Task<PeopleBaseRecord> GetActorAsync(
CancellationToken cancellationToken)
{
var key = $"TvdbPeople_{tvdbId.ToString(CultureInfo.InvariantCulture)}";
if (_memoryCache.TryGetValue(key, out PeopleBaseRecord people))
if (_memoryCache.TryGetValue(key, out PeopleBaseRecord? people)
&& people is not null)
{
return people;
}
Expand All @@ -327,7 +335,8 @@ public async Task<ArtworkExtendedRecord> GetImageAsync(
CancellationToken cancellationToken)
{
var key = $"TvdbArtwork_{imageTvdbId.ToString(CultureInfo.InvariantCulture)}";
if (_memoryCache.TryGetValue(key, out ArtworkExtendedRecord artwork))
if (_memoryCache.TryGetValue(key, out ArtworkExtendedRecord? artwork)
&& artwork is not null)
{
return artwork;
}
Expand All @@ -353,7 +362,8 @@ public async Task<SeriesExtendedRecord> GetSeriesImagesAsync(
CancellationToken cancellationToken)
{
var key = $"TvdbSeriesArtwork_{tvdbId.ToString(CultureInfo.InvariantCulture)}";
if (_memoryCache.TryGetValue(key, out SeriesExtendedRecord series))
if (_memoryCache.TryGetValue(key, out SeriesExtendedRecord? series)
&& series is not null)
{
return series;
}
Expand All @@ -374,7 +384,8 @@ public async Task<SeriesExtendedRecord> GetSeriesImagesAsync(
public async Task<IReadOnlyList<Language>> GetLanguagesAsync(CancellationToken cancellationToken)
{
var key = "TvdbLanguages";
if (_memoryCache.TryGetValue(key, out IReadOnlyList<Language> languages))
if (_memoryCache.TryGetValue(key, out IReadOnlyList<Language>? languages)
&& languages is not null)
{
return languages;
}
Expand All @@ -395,7 +406,8 @@ public async Task<IReadOnlyList<Language>> GetLanguagesAsync(CancellationToken c
public async Task<IReadOnlyList<ArtworkType>> GetArtworkTypeAsync(CancellationToken cancellationToken)
{
var key = "TvdbArtworkTypes";
if (_memoryCache.TryGetValue(key, out IReadOnlyList<ArtworkType> artworkTypes))
if (_memoryCache.TryGetValue(key, out IReadOnlyList<ArtworkType>? artworkTypes)
&& artworkTypes is not null)
{
return artworkTypes;
}
Expand Down
5 changes: 3 additions & 2 deletions Jellyfin.Plugin.Tvdb/TvdbPluginServiceRegistrator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MediaBrowser.Common.Plugins;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Plugins;
using Microsoft.Extensions.DependencyInjection;

namespace Jellyfin.Plugin.Tvdb
Expand All @@ -9,7 +10,7 @@ namespace Jellyfin.Plugin.Tvdb
public class TvdbPluginServiceRegistrator : IPluginServiceRegistrator
{
/// <inheritdoc />
public void RegisterServices(IServiceCollection serviceCollection)
public void RegisterServices(IServiceCollection serviceCollection, IServerApplicationHost applicationHost)
{
serviceCollection.AddSingleton<TvdbClientManager>();
}
Expand Down

0 comments on commit a820449

Please sign in to comment.