de-normalize item by name data. create counts during library scan for fast access.

This commit is contained in:
Luke Pulverenti
2013-09-10 14:56:00 -04:00
parent d078edfb96
commit 740a10a4e3
63 changed files with 1923 additions and 971 deletions

View File

@@ -1,11 +1,20 @@

using MediaBrowser.Model.Dto;
using System;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Entities.Audio
{
/// <summary>
/// Class Artist
/// </summary>
public class Artist : BaseItem, IItemByName
public class Artist : BaseItem, IItemByName, IHasMusicGenres
{
public Artist()
{
ItemCounts = new ItemByNameCounts();
UserItemCounts = new Dictionary<Guid, ItemByNameCounts>();
}
public string LastFmImageUrl { get; set; }
/// <summary>
@@ -17,5 +26,8 @@ namespace MediaBrowser.Controller.Entities.Audio
return "Artist-" + Name;
}
public ItemByNameCounts ItemCounts { get; set; }
public Dictionary<Guid, ItemByNameCounts> UserItemCounts { get; set; }
}
}

View File

@@ -9,7 +9,7 @@ namespace MediaBrowser.Controller.Entities.Audio
/// <summary>
/// Class Audio
/// </summary>
public class Audio : BaseItem, IHasMediaStreams, IHasAlbumArtist
public class Audio : BaseItem, IHasMediaStreams, IHasAlbumArtist, IHasArtist, IHasMusicGenres
{
public Audio()
{

View File

@@ -5,4 +5,9 @@ namespace MediaBrowser.Controller.Entities.Audio
{
string AlbumArtist { get; }
}
public interface IHasArtist
{
bool HasArtist(string name);
}
}

View File

@@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace MediaBrowser.Controller.Entities.Audio
{
public interface IHasMusicGenres
{
List<string> Genres { get; }
}
}

View File

@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using System.Runtime.Serialization;
namespace MediaBrowser.Controller.Entities.Audio
@@ -6,10 +7,15 @@ namespace MediaBrowser.Controller.Entities.Audio
/// <summary>
/// Class MusicAlbum
/// </summary>
public class MusicAlbum : Folder, IHasAlbumArtist
public class MusicAlbum : Folder, IHasAlbumArtist, IHasArtist, IHasMusicGenres
{
public MusicAlbum()
{
Artists = new string[] { };
}
public string LastFmImageUrl { get; set; }
/// <summary>
/// Songs will group into us so don't also include us in the index
/// </summary>
@@ -60,23 +66,17 @@ namespace MediaBrowser.Controller.Entities.Audio
/// <returns><c>true</c> if the specified artist has artist; otherwise, <c>false</c>.</returns>
public bool HasArtist(string artist)
{
return RecursiveChildren.OfType<Audio>().Any(i => i.HasArtist(artist));
return string.Equals(AlbumArtist, artist, StringComparison.OrdinalIgnoreCase)
|| Artists.Contains(artist, StringComparer.OrdinalIgnoreCase);
}
public string AlbumArtist
{
get
{
return RecursiveChildren
.OfType<Audio>()
.Select(i => i.AlbumArtist)
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
}
}
public string AlbumArtist { get; set; }
public string[] Artists { get; set; }
}
public class MusicAlbumDisc : Folder
{
}
}

View File

@@ -1,4 +1,7 @@

using MediaBrowser.Model.Dto;
using System;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Entities.Audio
{
/// <summary>
@@ -6,6 +9,12 @@ namespace MediaBrowser.Controller.Entities.Audio
/// </summary>
public class MusicGenre : BaseItem, IItemByName
{
public MusicGenre()
{
ItemCounts = new ItemByNameCounts();
UserItemCounts = new Dictionary<Guid, ItemByNameCounts>();
}
/// <summary>
/// Gets the user data key.
/// </summary>
@@ -14,5 +23,9 @@ namespace MediaBrowser.Controller.Entities.Audio
{
return "MusicGenre-" + Name;
}
public ItemByNameCounts ItemCounts { get; set; }
public Dictionary<Guid, ItemByNameCounts> UserItemCounts { get; set; }
}
}

View File

@@ -1537,5 +1537,58 @@ namespace MediaBrowser.Controller.Entities
// Refresh metadata
return RefreshMetadata(CancellationToken.None, forceSave: true);
}
/// <summary>
/// Validates that images within the item are still on the file system
/// </summary>
public void ValidateImages()
{
// Only validate paths from the same directory - need to copy to a list because we are going to potentially modify the collection below
var deletedKeys = Images
.ToList()
.Where(image => !File.Exists(image.Value))
.Select(i => i.Key)
.ToList();
// Now remove them from the dictionary
foreach (var key in deletedKeys)
{
Images.Remove(key);
}
}
/// <summary>
/// Validates that backdrops within the item are still on the file system
/// </summary>
public void ValidateBackdrops()
{
// Only validate paths from the same directory - need to copy to a list because we are going to potentially modify the collection below
var deletedImages = BackdropImagePaths
.Where(path => !File.Exists(path))
.ToList();
// Now remove them from the dictionary
foreach (var path in deletedImages)
{
BackdropImagePaths.Remove(path);
}
}
/// <summary>
/// Validates the screenshots.
/// </summary>
public void ValidateScreenshots()
{
// Only validate paths from the same directory - need to copy to a list because we are going to potentially modify the collection below
var deletedImages = ScreenshotImagePaths
.Where(path => !File.Exists(path))
.ToList();
// Now remove them from the dictionary
foreach (var path in deletedImages)
{
ScreenshotImagePaths.Remove(path);
}
}
}
}

View File

@@ -1,8 +1,17 @@

using MediaBrowser.Model.Dto;
using System;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Entities
{
public class GameGenre : BaseItem, IItemByName
{
public GameGenre()
{
ItemCounts = new ItemByNameCounts();
UserItemCounts = new Dictionary<Guid, ItemByNameCounts>();
}
/// <summary>
/// Gets the user data key.
/// </summary>
@@ -11,5 +20,9 @@ namespace MediaBrowser.Controller.Entities
{
return "GameGenre-" + Name;
}
public ItemByNameCounts ItemCounts { get; set; }
public Dictionary<Guid, ItemByNameCounts> UserItemCounts { get; set; }
}
}

View File

@@ -1,4 +1,7 @@

using MediaBrowser.Model.Dto;
using System;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Entities
{
/// <summary>
@@ -6,6 +9,12 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
public class Genre : BaseItem, IItemByName
{
public Genre()
{
ItemCounts = new ItemByNameCounts();
UserItemCounts = new Dictionary<Guid, ItemByNameCounts>();
}
/// <summary>
/// Gets the user data key.
/// </summary>
@@ -14,5 +23,9 @@ namespace MediaBrowser.Controller.Entities
{
return "Genre-" + Name;
}
public ItemByNameCounts ItemCounts { get; set; }
public Dictionary<Guid, ItemByNameCounts> UserItemCounts { get; set; }
}
}

View File

@@ -1,4 +1,7 @@

using MediaBrowser.Model.Dto;
using System;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Entities
{
/// <summary>
@@ -6,5 +9,8 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
public interface IItemByName
{
ItemByNameCounts ItemCounts { get; set; }
Dictionary<Guid, ItemByNameCounts> UserItemCounts { get; set; }
}
}

View File

@@ -1,9 +1,10 @@
using MediaBrowser.Model.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Model.Entities;
using System;
namespace MediaBrowser.Controller.Entities
{
public class MusicVideo : Video
public class MusicVideo : Video, IHasArtist, IHasMusicGenres
{
/// <summary>
/// Gets or sets the artist.

View File

@@ -1,4 +1,7 @@

using MediaBrowser.Model.Dto;
using System;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Entities
{
/// <summary>
@@ -6,6 +9,16 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
public class Person : BaseItem, IItemByName
{
public Person()
{
ItemCounts = new ItemByNameCounts();
UserItemCounts = new Dictionary<Guid, ItemByNameCounts>();
}
public ItemByNameCounts ItemCounts { get; set; }
public Dictionary<Guid, ItemByNameCounts> UserItemCounts { get; set; }
/// <summary>
/// Gets the user data key.
/// </summary>

View File

@@ -1,4 +1,7 @@

using MediaBrowser.Model.Dto;
using System;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Entities
{
/// <summary>
@@ -6,6 +9,12 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
public class Studio : BaseItem, IItemByName
{
public Studio()
{
ItemCounts = new ItemByNameCounts();
UserItemCounts = new Dictionary<Guid, ItemByNameCounts>();
}
/// <summary>
/// Gets the user data key.
/// </summary>
@@ -14,5 +23,9 @@ namespace MediaBrowser.Controller.Entities
{
return "Studio-" + Name;
}
public ItemByNameCounts ItemCounts { get; set; }
public Dictionary<Guid, ItemByNameCounts> UserItemCounts { get; set; }
}
}

View File

@@ -136,6 +136,11 @@ namespace MediaBrowser.Controller.Entities
get { return Video3DFormat.HasValue; }
}
public bool IsHd
{
get { return MediaStreams != null && MediaStreams.Any(i => i.Type == MediaStreamType.Video && i.Width.HasValue && i.Width.Value >= 1280); }
}
/// <summary>
/// Gets the type of the media.
/// </summary>

View File

@@ -1,4 +1,7 @@

using MediaBrowser.Model.Dto;
using System;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Entities
{
/// <summary>
@@ -6,6 +9,16 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
public class Year : BaseItem, IItemByName
{
public Year()
{
ItemCounts = new ItemByNameCounts();
UserItemCounts = new Dictionary<Guid, ItemByNameCounts>();
}
public ItemByNameCounts ItemCounts { get; set; }
public Dictionary<Guid, ItemByNameCounts> UserItemCounts { get; set; }
/// <summary>
/// Gets the user data key.
/// </summary>

View File

@@ -235,6 +235,38 @@ namespace MediaBrowser.Controller.Library
/// <returns>Task.</returns>
Task ValidateArtists(CancellationToken cancellationToken, IProgress<double> progress);
/// <summary>
/// Validates the music genres.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param>
/// <returns>Task.</returns>
Task ValidateMusicGenres(CancellationToken cancellationToken, IProgress<double> progress);
/// <summary>
/// Validates the game genres.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param>
/// <returns>Task.</returns>
Task ValidateGameGenres(CancellationToken cancellationToken, IProgress<double> progress);
/// <summary>
/// Validates the genres.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param>
/// <returns>Task.</returns>
Task ValidateGenres(CancellationToken cancellationToken, IProgress<double> progress);
/// <summary>
/// Validates the studios.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param>
/// <returns>Task.</returns>
Task ValidateStudios(CancellationToken cancellationToken, IProgress<double> progress);
/// <summary>
/// Occurs when [item added].
/// </summary>

View File

@@ -74,6 +74,7 @@
<Compile Include="Dto\IDtoService.cs" />
<Compile Include="Entities\AdultVideo.cs" />
<Compile Include="Entities\Audio\IHasAlbumArtist.cs" />
<Compile Include="Entities\Audio\IHasMusicGenres.cs" />
<Compile Include="Entities\Book.cs" />
<Compile Include="Configuration\IServerConfigurationManager.cs" />
<Compile Include="Entities\Audio\MusicGenre.cs" />
@@ -90,6 +91,7 @@
<Compile Include="Localization\ILocalizationManager.cs" />
<Compile Include="Notifications\INotificationsRepository.cs" />
<Compile Include="Notifications\NotificationUpdateEventArgs.cs" />
<Compile Include="Providers\IDynamicInfoProvider.cs" />
<Compile Include="Session\ISessionManager.cs" />
<Compile Include="Drawing\ImageExtensions.cs" />
<Compile Include="Drawing\ImageHeader.cs" />

View File

@@ -0,0 +1,10 @@

namespace MediaBrowser.Controller.Providers
{
/// <summary>
/// Marker interface for a provider that always runs
/// </summary>
public interface IDynamicInfoProvider
{
}
}