Skip to content

Commit

Permalink
Add suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
scampower3 committed Mar 10, 2024
1 parent 606f2ec commit 346df57
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions Jellyfin.Plugin.Tvdb/TvdbClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public TvdbClientManager(IApplicationHost applicationHost)

private static string? UserPin => TvdbPlugin.Instance?.Configuration.ApiKey;

private static int? CacheDurationInHours => TvdbPlugin.Instance?.Configuration.CacheDurationInHours;
private static int CacheDurationInHours => TvdbPlugin.Instance?.Configuration.CacheDurationInHours ?? 1;

private static int? CacheDurationInDays => TvdbPlugin.Instance?.Configuration.CacheDurationInDays;
private static int CacheDurationInDays => TvdbPlugin.Instance?.Configuration.CacheDurationInDays ?? 7;

/// <summary>
/// Logs in or refresh login to the tvdb api when needed.
Expand Down Expand Up @@ -112,7 +112,7 @@ public async Task<IReadOnlyList<SearchResult>> GetSeriesByNameAsync(
await LoginAsync().ConfigureAwait(false);
var searchResult = await searchClient.GetSearchResultsAsync(query: name, type: "series", limit: 5, cancellationToken: cancellationToken)
.ConfigureAwait(false);
_memoryCache.Set(key, searchResult.Data, TimeSpan.FromHours(CacheDurationInHours.GetValueOrDefault(1)));
_memoryCache.Set(key, searchResult.Data, TimeSpan.FromHours(CacheDurationInHours));
return searchResult.Data;
}

Expand All @@ -138,7 +138,7 @@ public async Task<SeriesBaseRecord> GetSeriesByIdAsync(
await LoginAsync().ConfigureAwait(false);
var seriesResult = await seriesClient.GetSeriesBaseAsync(id: tvdbId, cancellationToken: cancellationToken)
.ConfigureAwait(false);
_memoryCache.Set(key, seriesResult.Data, TimeSpan.FromHours(CacheDurationInHours.GetValueOrDefault(1)));
_memoryCache.Set(key, seriesResult.Data, TimeSpan.FromHours(CacheDurationInHours));
return seriesResult.Data;
}

Expand Down Expand Up @@ -168,7 +168,7 @@ public async Task<SeriesExtendedRecord> GetSeriesExtendedByIdAsync(
await LoginAsync().ConfigureAwait(false);
var seriesResult = await seriesClient.GetSeriesExtendedAsync(id: tvdbId, meta: meta, @short: small, cancellationToken: cancellationToken)
.ConfigureAwait(false);
_memoryCache.Set(key, seriesResult.Data, TimeSpan.FromHours(CacheDurationInHours.GetValueOrDefault(1)));
_memoryCache.Set(key, seriesResult.Data, TimeSpan.FromHours(CacheDurationInHours));
return seriesResult.Data;
}

Expand Down Expand Up @@ -196,7 +196,7 @@ public async Task<Data2> GetSeriesEpisodesAsync(
await LoginAsync().ConfigureAwait(false);
var seriesResult = await seriesClient.GetSeriesEpisodesAsync(id: tvdbId, season_type: seasonType, cancellationToken: cancellationToken, page: 0)
.ConfigureAwait(false);
_memoryCache.Set(key, seriesResult.Data, TimeSpan.FromHours(CacheDurationInHours.GetValueOrDefault(1)));
_memoryCache.Set(key, seriesResult.Data, TimeSpan.FromHours(CacheDurationInHours));
return seriesResult.Data;
}

Expand All @@ -222,7 +222,7 @@ public async Task<SeasonExtendedRecord> GetSeasonByIdAsync(
await LoginAsync().ConfigureAwait(false);
var seasonResult = await seasonClient.GetSeasonExtendedAsync(id: seasonTvdbId, cancellationToken: cancellationToken)
.ConfigureAwait(false);
_memoryCache.Set(key, seasonResult.Data, TimeSpan.FromHours(CacheDurationInHours.GetValueOrDefault(1)));
_memoryCache.Set(key, seasonResult.Data, TimeSpan.FromHours(CacheDurationInHours));
return seasonResult.Data;
}

Expand All @@ -248,7 +248,7 @@ public async Task<EpisodeExtendedRecord> GetEpisodesAsync(
await LoginAsync().ConfigureAwait(false);
var episodeResult = await episodeClient.GetEpisodeExtendedAsync(id: episodeTvdbId, meta: Meta.Translations, cancellationToken: cancellationToken)
.ConfigureAwait(false);
_memoryCache.Set(key, episodeResult.Data, TimeSpan.FromHours(CacheDurationInHours.GetValueOrDefault(1)));
_memoryCache.Set(key, episodeResult.Data, TimeSpan.FromHours(CacheDurationInHours));
return episodeResult.Data;
}

Expand All @@ -274,7 +274,7 @@ public async Task<IReadOnlyList<SearchByRemoteIdResult>> GetSeriesByRemoteIdAsyn
await LoginAsync().ConfigureAwait(false);
var searchResult = await searchClient.GetSearchResultsByRemoteIdAsync(remoteId: remoteId, cancellationToken: cancellationToken)
.ConfigureAwait(false);
_memoryCache.Set(key, searchResult.Data, TimeSpan.FromHours(CacheDurationInHours.GetValueOrDefault(1)));
_memoryCache.Set(key, searchResult.Data, TimeSpan.FromHours(CacheDurationInHours));
return searchResult.Data;
}

Expand All @@ -300,7 +300,7 @@ public async Task<PeopleBaseRecord> GetActorAsync(
await LoginAsync().ConfigureAwait(false);
var peopleResult = await peopleClient.GetPeopleBaseAsync(id: tvdbId, cancellationToken: cancellationToken)
.ConfigureAwait(false);
_memoryCache.Set(key, peopleResult.Data, TimeSpan.FromHours(CacheDurationInHours.GetValueOrDefault(1)));
_memoryCache.Set(key, peopleResult.Data, TimeSpan.FromHours(CacheDurationInHours));
return peopleResult.Data;
}

Expand All @@ -326,7 +326,7 @@ public async Task<ArtworkExtendedRecord> GetImageAsync(
await LoginAsync().ConfigureAwait(false);
var artworkResult = await artworkClient.GetArtworkExtendedAsync(id: imageTvdbId, cancellationToken: cancellationToken)
.ConfigureAwait(false);
_memoryCache.Set(key, artworkResult.Data, TimeSpan.FromHours(CacheDurationInHours.GetValueOrDefault(1)));
_memoryCache.Set(key, artworkResult.Data, TimeSpan.FromHours(CacheDurationInHours));
return artworkResult.Data;
}

Expand All @@ -352,7 +352,7 @@ public async Task<SeriesExtendedRecord> GetSeriesImagesAsync(
await LoginAsync().ConfigureAwait(false);
var seriesResult = await seriesClient.GetSeriesArtworksAsync(id: tvdbId, cancellationToken: cancellationToken)
.ConfigureAwait(false);
_memoryCache.Set(key, seriesResult.Data, TimeSpan.FromHours(CacheDurationInHours.GetValueOrDefault(1)));
_memoryCache.Set(key, seriesResult.Data, TimeSpan.FromHours(CacheDurationInHours));
return seriesResult.Data;
}

Expand All @@ -373,7 +373,7 @@ public async Task<IReadOnlyList<Language>> GetLanguagesAsync(CancellationToken c
await LoginAsync().ConfigureAwait(false);
var languagesResult = await languagesClient.GetAllLanguagesAsync(cancellationToken: cancellationToken)
.ConfigureAwait(false);
_memoryCache.Set(key, languagesResult.Data, TimeSpan.FromDays(CacheDurationInDays.GetValueOrDefault(1)));
_memoryCache.Set(key, languagesResult.Data, TimeSpan.FromDays(CacheDurationInDays));
return languagesResult.Data;
}

Expand All @@ -394,7 +394,7 @@ public async Task<IReadOnlyList<ArtworkType>> GetArtworkTypeAsync(CancellationTo
await LoginAsync().ConfigureAwait(false);
var artworkTypesResult = await artworkTypesClient.GetAllArtworkTypesAsync(cancellationToken: cancellationToken)
.ConfigureAwait(false);
_memoryCache.Set(key, artworkTypesResult.Data, TimeSpan.FromDays(CacheDurationInDays.GetValueOrDefault(1)));
_memoryCache.Set(key, artworkTypesResult.Data, TimeSpan.FromDays(CacheDurationInDays));
return artworkTypesResult.Data;
}

Expand Down Expand Up @@ -496,7 +496,7 @@ public async Task<IReadOnlyList<ArtworkType>> GetArtworkTypeAsync(CancellationTo
var tvdbId = seriesData.Episodes[0].Id?.ToString(CultureInfo.InvariantCulture);
if (key != null)
{
_memoryCache.Set(key, tvdbId, TimeSpan.FromHours(CacheDurationInHours.GetValueOrDefault(1)));
_memoryCache.Set(key, tvdbId, TimeSpan.FromHours(CacheDurationInHours));
}

return tvdbId;
Expand Down

0 comments on commit 346df57

Please sign in to comment.