Skip to content

Commit

Permalink
cleanup: style fixes
Browse files Browse the repository at this point in the history
- Remove brackets on singular blocks in id lookup.

- Use more `var` in guarded memory cache.

- Fix bracket position in content rating.
  • Loading branch information
revam committed Jun 16, 2024
1 parent c80d656 commit 0a0bf04
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
17 changes: 5 additions & 12 deletions Shokofin/IdLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,14 @@ public bool TryGetSeriesIdFromEpisodeId(string episodeId, [NotNullWhen(true)] ou

public bool TryGetSeriesIdFor(Series series, [NotNullWhen(true)] out string? seriesId)
{
if (series.ProviderIds.TryGetValue(ShokoSeriesId.Name, out seriesId!) && !string.IsNullOrEmpty(seriesId)) {
if (series.ProviderIds.TryGetValue(ShokoSeriesId.Name, out seriesId!) && !string.IsNullOrEmpty(seriesId))
return true;
}

if (TryGetSeriesIdFor(series.Path, out seriesId)) {
// Set the ShokoGroupId.Name and ShokoSeriesId.Name provider ids for the series, since it haven't been set again. It doesn't matter if it's not saved to the database, since we only need it while running the following code.
if (ApiManager.TryGetDefaultSeriesIdForSeriesId(seriesId, out var defaultSeriesId)) {
if (ApiManager.TryGetDefaultSeriesIdForSeriesId(seriesId, out var defaultSeriesId))
SeriesProvider.AddProviderIds(series, defaultSeriesId);
}
// Same as above, but only set the ShokoSeriesId.Name id.
else {
else
SeriesProvider.AddProviderIds(series, seriesId);
}
// Make sure the presentation unique is not cached, so we won't reuse the cache key.
series.PresentationUniqueKey = null;
return true;
Expand Down Expand Up @@ -258,14 +253,12 @@ public bool TryGetEpisodeIdsFor(string path, [NotNullWhen(true)] out List<string
public bool TryGetEpisodeIdsFor(BaseItem item, [NotNullWhen(true)] out List<string>? episodeIds)
{
// This will account for virtual episodes and existing episodes
if (item.ProviderIds.TryGetValue(ShokoFileId.Name, out var fileId) && item.ProviderIds.TryGetValue(ShokoSeriesId.Name, out var seriesId) && ApiManager.TryGetEpisodeIdsForFileId(fileId, seriesId, out episodeIds!)) {
if (item.ProviderIds.TryGetValue(ShokoFileId.Name, out var fileId) && item.ProviderIds.TryGetValue(ShokoSeriesId.Name, out var seriesId) && ApiManager.TryGetEpisodeIdsForFileId(fileId, seriesId, out episodeIds!))
return true;
}

// This will account for new episodes that haven't received their first metadata update yet.
if (TryGetEpisodeIdsFor(item.Path, out episodeIds)) {
if (TryGetEpisodeIdsFor(item.Path, out episodeIds))
return true;
}

return false;
}
Expand Down
3 changes: 1 addition & 2 deletions Shokofin/Utils/ContentRating.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ private static bool TryConvertRatingFromText(string? value, out TvRating content
private static string? ConvertRatingToText(TvRating value, IEnumerable<TvContentIndicator>? contentIndicators)
{
var field = value.GetType().GetField(value.ToString());
if (field?.GetCustomAttributes(typeof(DescriptionAttribute), false) is DescriptionAttribute[] attributes && attributes.Length != 0)
{
if (field?.GetCustomAttributes(typeof(DescriptionAttribute), false) is DescriptionAttribute[] attributes && attributes.Length != 0) {
var contentRating = attributes.First().Description;
var allowedIndicators = (
(field.GetCustomAttributes(typeof(TvContentIndicatorsAttribute), false) as TvContentIndicatorsAttribute[] ?? Array.Empty<TvContentIndicatorsAttribute>()).FirstOrDefault()?.Values ?? Array.Empty<TvContentIndicator>()
Expand Down
8 changes: 4 additions & 4 deletions Shokofin/Utils/GuardedMemoryCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public TItem GetOrCreate<TItem>(object key, Action<TItem> foundAction, Func<ICac
return value;
}

using ICacheEntry entry = Cache.CreateEntry(key);
using var entry = Cache.CreateEntry(key);
createOptions ??= CacheEntryOptions;
if (createOptions != null)
entry.SetOptions(createOptions);
Expand Down Expand Up @@ -86,7 +86,7 @@ public async Task<TItem> GetOrCreateAsync<TItem>(object key, Action<TItem> found
return value;
}

using ICacheEntry entry = Cache.CreateEntry(key);
using var entry = Cache.CreateEntry(key);
createOptions ??= CacheEntryOptions;
if (createOptions != null)
entry.SetOptions(createOptions);
Expand Down Expand Up @@ -114,7 +114,7 @@ public TItem GetOrCreate<TItem>(object key, Func<ICacheEntry, TItem> createFacto
if (TryGetValue(key, out value))
return value;

using ICacheEntry entry = Cache.CreateEntry(key);
using var entry = Cache.CreateEntry(key);
createOptions ??= CacheEntryOptions;
if (createOptions != null)
entry.SetOptions(createOptions);
Expand Down Expand Up @@ -142,7 +142,7 @@ public async Task<TItem> GetOrCreateAsync<TItem>(object key, Func<ICacheEntry, T
if (TryGetValue(key, out value))
return value;

using ICacheEntry entry = Cache.CreateEntry(key);
using var entry = Cache.CreateEntry(key);
createOptions ??= CacheEntryOptions;
if (createOptions != null)
entry.SetOptions(createOptions);
Expand Down

0 comments on commit 0a0bf04

Please sign in to comment.