Skip to content

Commit

Permalink
Merge pull request #7049 from crobibero/warn40219
Browse files Browse the repository at this point in the history
  • Loading branch information
Bond-009 committed Dec 30, 2021
2 parents bb713d1 + 7bfc6b5 commit b2a2bdb
Show file tree
Hide file tree
Showing 50 changed files with 231 additions and 265 deletions.
10 changes: 5 additions & 5 deletions Emby.Drawing/ImageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public sealed class ImageProcessor : IImageProcessor, IDisposable
public async Task ProcessImage(ImageProcessingOptions options, Stream toStream)
{
var file = await ProcessImage(options).ConfigureAwait(false);
using (var fileStream = AsyncFile.OpenRead(file.path))
using (var fileStream = AsyncFile.OpenRead(file.Path))
{
await fileStream.CopyToAsync(toStream).ConfigureAwait(false);
}
Expand All @@ -116,7 +116,7 @@ public bool SupportsTransparency(string path)
=> _transparentImageTypes.Contains(Path.GetExtension(path));

/// <inheritdoc />
public async Task<(string path, string? mimeType, DateTime dateModified)> ProcessImage(ImageProcessingOptions options)
public async Task<(string Path, string? MimeType, DateTime DateModified)> ProcessImage(ImageProcessingOptions options)
{
ItemImageInfo originalImage = options.Image;
BaseItem item = options.Item;
Expand All @@ -135,14 +135,14 @@ public async Task<(string path, string? mimeType, DateTime dateModified)> Proces
}

var supportedImageInfo = await GetSupportedImage(originalImagePath, dateModified).ConfigureAwait(false);
originalImagePath = supportedImageInfo.path;
originalImagePath = supportedImageInfo.Path;

if (!File.Exists(originalImagePath))
{
return (originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified);
}

dateModified = supportedImageInfo.dateModified;
dateModified = supportedImageInfo.DateModified;
bool requiresTransparency = _transparentImageTypes.Contains(Path.GetExtension(originalImagePath));

bool autoOrient = false;
Expand Down Expand Up @@ -436,7 +436,7 @@ public string GetImageCacheTag(BaseItem item, ChapterInfo chapter)
.ToString("N", CultureInfo.InvariantCulture);
}

private async Task<(string path, DateTime dateModified)> GetSupportedImage(string originalImagePath, DateTime dateModified)
private async Task<(string Path, DateTime DateModified)> GetSupportedImage(string originalImagePath, DateTime dateModified)
{
var inputFormat = Path.GetExtension(originalImagePath)
.TrimStart('.')
Expand Down
6 changes: 3 additions & 3 deletions Emby.Naming/TV/SeasonPathParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static SeasonPathParserResult Parse(string path, bool supportSpecialAlias
/// <param name="supportSpecialAliases">if set to <c>true</c> [support special aliases].</param>
/// <param name="supportNumericSeasonFolders">if set to <c>true</c> [support numeric season folders].</param>
/// <returns>System.Nullable{System.Int32}.</returns>
private static (int? seasonNumber, bool isSeasonFolder) GetSeasonNumberFromPath(
private static (int? SeasonNumber, bool IsSeasonFolder) GetSeasonNumberFromPath(
string path,
bool supportSpecialAliases,
bool supportNumericSeasonFolders)
Expand Down Expand Up @@ -99,7 +99,7 @@ public static SeasonPathParserResult Parse(string path, bool supportSpecialAlias
if (filename.Contains(name, StringComparison.OrdinalIgnoreCase))
{
var result = GetSeasonNumberFromPathSubstring(filename.Replace(name, " ", StringComparison.OrdinalIgnoreCase));
if (result.seasonNumber.HasValue)
if (result.SeasonNumber.HasValue)
{
return result;
}
Expand Down Expand Up @@ -142,7 +142,7 @@ private static bool TryGetSeasonNumberFromPart(ReadOnlySpan<char> part, out int
/// </summary>
/// <param name="path">The path.</param>
/// <returns>System.Nullable{System.Int32}.</returns>
private static (int? seasonNumber, bool isSeasonFolder) GetSeasonNumberFromPathSubstring(ReadOnlySpan<char> path)
private static (int? SeasonNumber, bool IsSeasonFolder) GetSeasonNumberFromPathSubstring(ReadOnlySpan<char> path)
{
var numericStart = -1;
var length = 0;
Expand Down
8 changes: 3 additions & 5 deletions Emby.Server.Implementations/Channels/ChannelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,14 @@ public Task DeleteItem(BaseItem item)
var internalChannel = _libraryManager.GetItemById(item.ChannelId);
if (internalChannel == null)
{
throw new ArgumentException();
throw new ArgumentException(nameof(item.ChannelId));
}

var channel = Channels.FirstOrDefault(i => GetInternalChannelId(i.Name).Equals(internalChannel.Id));

var supportsDelete = channel as ISupportsDelete;

if (supportsDelete == null)
if (channel is not ISupportsDelete supportsDelete)
{
throw new ArgumentException();
throw new ArgumentException(nameof(channel));
}

return supportsDelete.DeleteItem(item.ExternalId, CancellationToken.None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public async Task<BoxSet> CreateCollectionAsync(CollectionCreationOptions option

if (parentFolder == null)
{
throw new ArgumentException();
throw new ArgumentException(nameof(parentFolder));
}

var path = Path.Combine(parentFolder.Path, folderName);
Expand Down
118 changes: 41 additions & 77 deletions Emby.Server.Implementations/Data/SqliteItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,40 +248,6 @@ public class SqliteItemRepository : BaseSqliteRepository, IItemRepository
BaseItemKind.AudioBook
};

private static readonly Type[] _knownTypes =
{
typeof(LiveTvProgram),
typeof(LiveTvChannel),
typeof(Series),
typeof(Audio),
typeof(MusicAlbum),
typeof(MusicArtist),
typeof(MusicGenre),
typeof(MusicVideo),
typeof(Movie),
typeof(Playlist),
typeof(AudioBook),
typeof(Trailer),
typeof(BoxSet),
typeof(Episode),
typeof(Season),
typeof(Series),
typeof(Book),
typeof(CollectionFolder),
typeof(Folder),
typeof(Genre),
typeof(Person),
typeof(Photo),
typeof(PhotoAlbum),
typeof(Studio),
typeof(UserRootFolder),
typeof(UserView),
typeof(Video),
typeof(Year),
typeof(Channel),
typeof(AggregateFolder)
};

private static readonly Dictionary<BaseItemKind, string> _baseItemKindNames = new()
{
{ BaseItemKind.AggregateFolder, typeof(AggregateFolder).FullName },
Expand Down Expand Up @@ -688,13 +654,13 @@ public void SaveItems(IEnumerable<BaseItem> items, CancellationToken cancellatio
connection.RunInTransaction(
db =>
{
SaveItemsInTranscation(db, tuples);
SaveItemsInTransaction(db, tuples);
},
TransactionMode);
}
}

private void SaveItemsInTranscation(IDatabaseConnection db, IEnumerable<(BaseItem, List<Guid>, BaseItem, string, List<string>)> tuples)
private void SaveItemsInTransaction(IDatabaseConnection db, IEnumerable<(BaseItem Item, List<Guid> AncestorIds, BaseItem TopParent, string UserDataKey, List<string> InheritedTags)> tuples)
{
var statements = PrepareAll(db, new string[]
{
Expand All @@ -713,17 +679,17 @@ private void SaveItemsInTranscation(IDatabaseConnection db, IEnumerable<(BaseIte
saveItemStatement.Reset();
}

var item = tuple.Item1;
var topParent = tuple.Item3;
var userDataKey = tuple.Item4;
var item = tuple.Item;
var topParent = tuple.TopParent;
var userDataKey = tuple.UserDataKey;

SaveItem(item, topParent, userDataKey, saveItemStatement);

var inheritedTags = tuple.Item5;
var inheritedTags = tuple.InheritedTags;

if (item.SupportsAncestors)
{
UpdateAncestors(item.Id, tuple.Item2, db, deleteAncestorsStatement);
UpdateAncestors(item.Id, tuple.AncestorIds, db, deleteAncestorsStatement);
}

UpdateItemValues(item.Id, GetItemValuesToSave(item, inheritedTags), db);
Expand Down Expand Up @@ -2201,7 +2167,7 @@ private static bool EnableJoinUserData(InternalItemsQuery query)
return false;
}

var sortingFields = new HashSet<string>(query.OrderBy.Select(i => i.Item1), StringComparer.OrdinalIgnoreCase);
var sortingFields = new HashSet<string>(query.OrderBy.Select(i => i.OrderBy), StringComparer.OrdinalIgnoreCase);

return sortingFields.Contains(ItemSortBy.IsFavoriteOrLiked)
|| sortingFields.Contains(ItemSortBy.IsPlayed)
Expand Down Expand Up @@ -3049,88 +3015,86 @@ private string GetOrderByText(InternalItemsQuery query)

return " ORDER BY " + string.Join(',', orderBy.Select(i =>
{
var columnMap = MapOrderByField(i.Item1, query);
var sortOrder = i.Item2 == SortOrder.Ascending ? "ASC" : "DESC";
var columnMap = MapOrderByField(i.OrderBy, query);
return columnMap.Item1 + " " + sortOrder;
return columnMap.SortBy + " " + columnMap.SortOrder;
}));
}

private (string, bool) MapOrderByField(string name, InternalItemsQuery query)
private (string SortBy, SortOrder SortOrder) MapOrderByField(string name, InternalItemsQuery query)
{
if (string.Equals(name, ItemSortBy.AirTime, StringComparison.OrdinalIgnoreCase))
{
// TODO
return ("SortName", false);
return ("SortName", SortOrder.Descending);
}
else if (string.Equals(name, ItemSortBy.Runtime, StringComparison.OrdinalIgnoreCase))
{
return ("RuntimeTicks", false);
return ("RuntimeTicks", SortOrder.Descending);
}
else if (string.Equals(name, ItemSortBy.Random, StringComparison.OrdinalIgnoreCase))
{
return ("RANDOM()", false);
return ("RANDOM()", SortOrder.Descending);
}
else if (string.Equals(name, ItemSortBy.DatePlayed, StringComparison.OrdinalIgnoreCase))
{
if (query.GroupBySeriesPresentationUniqueKey)
{
return ("MAX(LastPlayedDate)", false);
return ("MAX(LastPlayedDate)", SortOrder.Descending);
}

return ("LastPlayedDate", false);
return ("LastPlayedDate", SortOrder.Descending);
}
else if (string.Equals(name, ItemSortBy.PlayCount, StringComparison.OrdinalIgnoreCase))
{
return ("PlayCount", false);
return ("PlayCount", SortOrder.Descending);
}
else if (string.Equals(name, ItemSortBy.IsFavoriteOrLiked, StringComparison.OrdinalIgnoreCase))
{
return ("(Select Case When IsFavorite is null Then 0 Else IsFavorite End )", true);
return ("(Select Case When IsFavorite is null Then 0 Else IsFavorite End )", SortOrder.Ascending);
}
else if (string.Equals(name, ItemSortBy.IsFolder, StringComparison.OrdinalIgnoreCase))
{
return ("IsFolder", true);
return ("IsFolder", SortOrder.Ascending);
}
else if (string.Equals(name, ItemSortBy.IsPlayed, StringComparison.OrdinalIgnoreCase))
{
return ("played", true);
return ("played", SortOrder.Ascending);
}
else if (string.Equals(name, ItemSortBy.IsUnplayed, StringComparison.OrdinalIgnoreCase))
{
return ("played", false);
return ("played", SortOrder.Descending);
}
else if (string.Equals(name, ItemSortBy.DateLastContentAdded, StringComparison.OrdinalIgnoreCase))
{
return ("DateLastMediaAdded", false);
return ("DateLastMediaAdded", SortOrder.Descending);
}
else if (string.Equals(name, ItemSortBy.Artist, StringComparison.OrdinalIgnoreCase))
{
return ("(select CleanValue from itemvalues where ItemId=Guid and Type=0 LIMIT 1)", false);
return ("(select CleanValue from itemvalues where ItemId=Guid and Type=0 LIMIT 1)", SortOrder.Descending);
}
else if (string.Equals(name, ItemSortBy.AlbumArtist, StringComparison.OrdinalIgnoreCase))
{
return ("(select CleanValue from itemvalues where ItemId=Guid and Type=1 LIMIT 1)", false);
return ("(select CleanValue from itemvalues where ItemId=Guid and Type=1 LIMIT 1)", SortOrder.Descending);
}
else if (string.Equals(name, ItemSortBy.OfficialRating, StringComparison.OrdinalIgnoreCase))
{
return ("InheritedParentalRatingValue", false);
return ("InheritedParentalRatingValue", SortOrder.Descending);
}
else if (string.Equals(name, ItemSortBy.Studio, StringComparison.OrdinalIgnoreCase))
{
return ("(select CleanValue from itemvalues where ItemId=Guid and Type=3 LIMIT 1)", false);
return ("(select CleanValue from itemvalues where ItemId=Guid and Type=3 LIMIT 1)", SortOrder.Descending);
}
else if (string.Equals(name, ItemSortBy.SeriesDatePlayed, StringComparison.OrdinalIgnoreCase))
{
return ("(Select MAX(LastPlayedDate) from TypedBaseItems B" + GetJoinUserDataText(query) + " where Played=1 and B.SeriesPresentationUniqueKey=A.PresentationUniqueKey)", false);
return ("(Select MAX(LastPlayedDate) from TypedBaseItems B" + GetJoinUserDataText(query) + " where Played=1 and B.SeriesPresentationUniqueKey=A.PresentationUniqueKey)", SortOrder.Descending);
}
else if (string.Equals(name, ItemSortBy.SeriesSortName, StringComparison.OrdinalIgnoreCase))
{
return ("SeriesName", false);
return ("SeriesName", SortOrder.Descending);
}

return (name, false);
return (name, SortOrder.Descending);
}

public List<Guid> GetItemIdsList(InternalItemsQuery query)
Expand Down Expand Up @@ -5230,32 +5194,32 @@ private void UpdateAncestors(Guid itemId, List<Guid> ancestorIds, IDatabaseConne
}
}

public QueryResult<(BaseItem, ItemCounts)> GetAllArtists(InternalItemsQuery query)
public QueryResult<(BaseItem Item, ItemCounts ItemCounts)> GetAllArtists(InternalItemsQuery query)
{
return GetItemValues(query, new[] { 0, 1 }, typeof(MusicArtist).FullName);
}

public QueryResult<(BaseItem, ItemCounts)> GetArtists(InternalItemsQuery query)
public QueryResult<(BaseItem Item, ItemCounts ItemCounts)> GetArtists(InternalItemsQuery query)
{
return GetItemValues(query, new[] { 0 }, typeof(MusicArtist).FullName);
}

public QueryResult<(BaseItem, ItemCounts)> GetAlbumArtists(InternalItemsQuery query)
public QueryResult<(BaseItem Item, ItemCounts ItemCounts)> GetAlbumArtists(InternalItemsQuery query)
{
return GetItemValues(query, new[] { 1 }, typeof(MusicArtist).FullName);
}

public QueryResult<(BaseItem, ItemCounts)> GetStudios(InternalItemsQuery query)
public QueryResult<(BaseItem Item, ItemCounts ItemCounts)> GetStudios(InternalItemsQuery query)
{
return GetItemValues(query, new[] { 3 }, typeof(Studio).FullName);
}

public QueryResult<(BaseItem, ItemCounts)> GetGenres(InternalItemsQuery query)
public QueryResult<(BaseItem Item, ItemCounts ItemCounts)> GetGenres(InternalItemsQuery query)
{
return GetItemValues(query, new[] { 2 }, typeof(Genre).FullName);
}

public QueryResult<(BaseItem, ItemCounts)> GetMusicGenres(InternalItemsQuery query)
public QueryResult<(BaseItem Item, ItemCounts ItemCounts)> GetMusicGenres(InternalItemsQuery query)
{
return GetItemValues(query, new[] { 2 }, typeof(MusicGenre).FullName);
}
Expand Down Expand Up @@ -5351,7 +5315,7 @@ private List<string> GetItemValueNames(int[] itemValueTypes, IReadOnlyList<strin
return list;
}

private QueryResult<(BaseItem, ItemCounts)> GetItemValues(InternalItemsQuery query, int[] itemValueTypes, string returnType)
private QueryResult<(BaseItem Item, ItemCounts ItemCounts)> GetItemValues(InternalItemsQuery query, int[] itemValueTypes, string returnType)
{
if (query == null)
{
Expand Down Expand Up @@ -5676,7 +5640,7 @@ private static ItemCounts GetItemCounts(IReadOnlyList<ResultSetValue> reader, in
return counts;
}

private List<(int, string)> GetItemValuesToSave(BaseItem item, List<string> inheritedTags)
private List<(int MagicNumber, string Value)> GetItemValuesToSave(BaseItem item, List<string> inheritedTags)
{
var list = new List<(int, string)>();

Expand All @@ -5701,7 +5665,7 @@ private List<(int, string)> GetItemValuesToSave(BaseItem item, List<string> inhe
return list;
}

private void UpdateItemValues(Guid itemId, List<(int, string)> values, IDatabaseConnection db)
private void UpdateItemValues(Guid itemId, List<(int MagicNumber, string Value)> values, IDatabaseConnection db)
{
if (itemId.Equals(Guid.Empty))
{
Expand All @@ -5723,7 +5687,7 @@ private void UpdateItemValues(Guid itemId, List<(int, string)> values, IDatabase
InsertItemValues(guidBlob, values, db);
}

private void InsertItemValues(byte[] idBlob, List<(int, string)> values, IDatabaseConnection db)
private void InsertItemValues(byte[] idBlob, List<(int MagicNumber, string Value)> values, IDatabaseConnection db)
{
const int Limit = 100;
var startIndex = 0;
Expand Down Expand Up @@ -5755,15 +5719,15 @@ private void InsertItemValues(byte[] idBlob, List<(int, string)> values, IDataba

var currentValueInfo = values[i];

var itemValue = currentValueInfo.Item2;
var itemValue = currentValueInfo.Value;

// Don't save if invalid
if (string.IsNullOrWhiteSpace(itemValue))
{
continue;
}

statement.TryBind("@Type" + index, currentValueInfo.Item1);
statement.TryBind("@Type" + index, currentValueInfo.MagicNumber);
statement.TryBind("@Value" + index, itemValue);
statement.TryBind("@CleanValue" + index, GetCleanValue(itemValue));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ private IEnumerable<T> TranslatePhysicalItemToUserLibrary<T>(T item, User user,
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
Expand Down
Loading

0 comments on commit b2a2bdb

Please sign in to comment.