denormalize seasonid

This commit is contained in:
Luke Pulverenti 2016-07-05 01:40:18 -04:00
parent 73e2b1f283
commit 2772d59559
11 changed files with 135 additions and 166 deletions

View File

@ -117,7 +117,7 @@ namespace MediaBrowser.Api
config.EnableStandaloneMusicKeys = true; config.EnableStandaloneMusicKeys = true;
config.EnableCaseSensitiveItemIds = true; config.EnableCaseSensitiveItemIds = true;
//config.EnableFolderView = true; //config.EnableFolderView = true;
config.SchemaVersion = 99; config.SchemaVersion = 100;
} }
public void Post(UpdateStartupConfiguration request) public void Post(UpdateStartupConfiguration request)

View File

@ -13,7 +13,6 @@ namespace MediaBrowser.Controller.Entities.TV
/// </summary> /// </summary>
public class Episode : Video, IHasTrailers, IHasLookupInfo<EpisodeInfo>, IHasSeries public class Episode : Video, IHasTrailers, IHasLookupInfo<EpisodeInfo>, IHasSeries
{ {
public Episode() public Episode()
{ {
RemoteTrailers = new List<MediaUrl>(); RemoteTrailers = new List<MediaUrl>();
@ -181,6 +180,12 @@ namespace MediaBrowser.Controller.Entities.TV
{ {
var series = Series; var series = Series;
return series == null ? SeriesName : series.Name; return series == null ? SeriesName : series.Name;
}
public Guid? FindSeasonId()
{
var season = Season;
return season == null ? (Guid?)null : season.Id;
} }
/// <summary> /// <summary>
@ -243,21 +248,7 @@ namespace MediaBrowser.Controller.Entities.TV
} }
[IgnoreDataMember] [IgnoreDataMember]
public Guid? SeasonId public Guid? SeasonId { get; set; }
{
get
{
// First see if the parent is a Season
var season = Season;
if (season != null)
{
return season.Id;
}
return null;
}
}
public override IEnumerable<Guid> GetAncestorIds() public override IEnumerable<Guid> GetAncestorIds()
{ {

View File

@ -954,6 +954,16 @@ namespace MediaBrowser.Model.Dto
get { return ImageTags != null && ImageTags.ContainsKey(ImageType.Thumb); } get { return ImageTags != null && ImageTags.ContainsKey(ImageType.Thumb); }
} }
/// <summary>
/// Gets a value indicating whether this instance has thumb.
/// </summary>
/// <value><c>true</c> if this instance has thumb; otherwise, <c>false</c>.</value>
[IgnoreDataMember]
public bool HasBackdrop
{
get { return (BackdropImageTags != null && BackdropImageTags.Count > 0) || (ParentBackdropImageTags != null && ParentBackdropImageTags.Count > 0); }
}
/// <summary> /// <summary>
/// Gets a value indicating whether this instance has primary image. /// Gets a value indicating whether this instance has primary image.
/// </summary> /// </summary>

View File

@ -429,7 +429,8 @@ namespace MediaBrowser.Providers.TV
IndexNumber = episodeNumber, IndexNumber = episodeNumber,
ParentIndexNumber = seasonNumber, ParentIndexNumber = seasonNumber,
Id = _libraryManager.GetNewItemId((series.Id + seasonNumber.ToString(_usCulture) + name), typeof(Episode)), Id = _libraryManager.GetNewItemId((series.Id + seasonNumber.ToString(_usCulture) + name), typeof(Episode)),
IsVirtualItem = true IsVirtualItem = true,
SeasonId = season == null ? (Guid?)null : season.Id
}; };
episode.SetParent(season); episode.SetParent(season);

View File

@ -663,19 +663,12 @@ namespace MediaBrowser.Server.Implementations.Dto
dto.GameSystem = item.GameSystemName; dto.GameSystem = item.GameSystemName;
} }
private List<string> GetBackdropImageTags(BaseItem item, int limit) private List<string> GetImageTags(BaseItem item, List<ItemImageInfo> images)
{ {
return GetCacheTags(item, ImageType.Backdrop, limit).ToList(); return images
} .Select(p => GetImageCacheTag(item, p))
.Where(i => i != null)
private List<string> GetScreenshotImageTags(BaseItem item, int limit) .ToList();
{
var hasScreenshots = item as IHasScreenshots;
if (hasScreenshots == null)
{
return new List<string>();
}
return GetCacheTags(item, ImageType.Screenshot, limit).ToList();
} }
private IEnumerable<string> GetCacheTags(BaseItem item, ImageType type, int limit) private IEnumerable<string> GetCacheTags(BaseItem item, ImageType type, int limit)
@ -850,53 +843,6 @@ namespace MediaBrowser.Server.Implementations.Dto
} }
} }
/// <summary>
/// If an item does not any backdrops, this can be used to find the first parent that does have one
/// </summary>
/// <param name="item">The item.</param>
/// <param name="owner">The owner.</param>
/// <returns>BaseItem.</returns>
private BaseItem GetParentBackdropItem(BaseItem item, BaseItem owner)
{
var parent = item.GetParent() ?? owner;
while (parent != null)
{
if (parent.GetImages(ImageType.Backdrop).Any())
{
return parent;
}
parent = parent.GetParent();
}
return null;
}
/// <summary>
/// If an item does not have a logo, this can be used to find the first parent that does have one
/// </summary>
/// <param name="item">The item.</param>
/// <param name="type">The type.</param>
/// <param name="owner">The owner.</param>
/// <returns>BaseItem.</returns>
private BaseItem GetParentImageItem(BaseItem item, ImageType type, BaseItem owner)
{
var parent = item.GetParent() ?? owner;
while (parent != null)
{
if (parent.HasImage(type))
{
return parent;
}
parent = parent.GetParent();
}
return null;
}
/// <summary> /// <summary>
/// Gets the chapter info dto. /// Gets the chapter info dto.
/// </summary> /// </summary>
@ -1027,7 +973,7 @@ namespace MediaBrowser.Server.Implementations.Dto
var backdropLimit = options.GetImageLimit(ImageType.Backdrop); var backdropLimit = options.GetImageLimit(ImageType.Backdrop);
if (backdropLimit > 0) if (backdropLimit > 0)
{ {
dto.BackdropImageTags = GetBackdropImageTags(item, backdropLimit); dto.BackdropImageTags = GetImageTags(item, item.GetImages(ImageType.Backdrop).Take(backdropLimit).ToList());
} }
if (fields.Contains(ItemFields.ScreenshotImageTags)) if (fields.Contains(ItemFields.ScreenshotImageTags))
@ -1035,7 +981,7 @@ namespace MediaBrowser.Server.Implementations.Dto
var screenshotLimit = options.GetImageLimit(ImageType.Screenshot); var screenshotLimit = options.GetImageLimit(ImageType.Screenshot);
if (screenshotLimit > 0) if (screenshotLimit > 0)
{ {
dto.ScreenshotImageTags = GetScreenshotImageTags(item, screenshotLimit); dto.BackdropImageTags = GetImageTags(item, item.GetImages(ImageType.Screenshot).Take(screenshotLimit).ToList());
} }
} }
@ -1064,6 +1010,7 @@ namespace MediaBrowser.Server.Implementations.Dto
dto.Id = GetDtoId(item); dto.Id = GetDtoId(item);
dto.IndexNumber = item.IndexNumber; dto.IndexNumber = item.IndexNumber;
dto.ParentIndexNumber = item.ParentIndexNumber;
dto.IsFolder = item.IsFolder; dto.IsFolder = item.IsFolder;
dto.MediaType = item.MediaType; dto.MediaType = item.MediaType;
dto.LocationType = item.LocationType; dto.LocationType = item.LocationType;
@ -1126,18 +1073,6 @@ namespace MediaBrowser.Server.Implementations.Dto
dto.ShortOverview = item.ShortOverview; dto.ShortOverview = item.ShortOverview;
} }
// If there are no backdrops, indicate what parent has them in case the Ui wants to allow inheritance
if (backdropLimit > 0 && dto.BackdropImageTags.Count == 0)
{
var parentWithBackdrop = GetParentBackdropItem(item, owner);
if (parentWithBackdrop != null)
{
dto.ParentBackdropItemId = GetDtoId(parentWithBackdrop);
dto.ParentBackdropImageTags = GetBackdropImageTags(parentWithBackdrop, backdropLimit);
}
}
if (fields.Contains(ItemFields.ParentId)) if (fields.Contains(ItemFields.ParentId))
{ {
var displayParentId = item.DisplayParentId; var displayParentId = item.DisplayParentId;
@ -1147,46 +1082,7 @@ namespace MediaBrowser.Server.Implementations.Dto
} }
} }
dto.ParentIndexNumber = item.ParentIndexNumber; AddInheritedImages(dto, item, options, owner);
// If there is no logo, indicate what parent has one in case the Ui wants to allow inheritance
if (!dto.HasLogo && options.GetImageLimit(ImageType.Logo) > 0)
{
var parentWithLogo = GetParentImageItem(item, ImageType.Logo, owner);
if (parentWithLogo != null)
{
dto.ParentLogoItemId = GetDtoId(parentWithLogo);
dto.ParentLogoImageTag = GetImageCacheTag(parentWithLogo, ImageType.Logo);
}
}
// If there is no art, indicate what parent has one in case the Ui wants to allow inheritance
if (!dto.HasArtImage && options.GetImageLimit(ImageType.Art) > 0)
{
var parentWithImage = GetParentImageItem(item, ImageType.Art, owner);
if (parentWithImage != null)
{
dto.ParentArtItemId = GetDtoId(parentWithImage);
dto.ParentArtImageTag = GetImageCacheTag(parentWithImage, ImageType.Art);
}
}
// If there is no thumb, indicate what parent has one in case the Ui wants to allow inheritance
if (!dto.HasThumb && options.GetImageLimit(ImageType.Thumb) > 0)
{
var parentWithImage = GetParentImageItem(item, ImageType.Thumb, owner);
if (parentWithImage != null)
{
dto.ParentThumbItemId = GetDtoId(parentWithImage);
dto.ParentThumbImageTag = GetImageCacheTag(parentWithImage, ImageType.Thumb);
}
}
if (fields.Contains(ItemFields.Path)) if (fields.Contains(ItemFields.Path))
{ {
@ -1420,33 +1316,36 @@ namespace MediaBrowser.Server.Implementations.Dto
dto.SeasonName = episode.SeasonName; dto.SeasonName = episode.SeasonName;
var episodeSeries = episode.Series; Series episodeSeries = null;
if (episodeSeries != null) if (fields.Contains(ItemFields.SeriesGenres))
{ {
if (fields.Contains(ItemFields.SeriesGenres)) episodeSeries = episodeSeries ?? episode.Series;
if (episodeSeries != null)
{ {
dto.SeriesGenres = episodeSeries.Genres.ToList(); dto.SeriesGenres = episodeSeries.Genres.ToList();
} }
}
episodeSeries = episodeSeries ?? episode.Series;
if (episodeSeries != null)
{
dto.SeriesId = GetDtoId(episodeSeries); dto.SeriesId = GetDtoId(episodeSeries);
}
if (fields.Contains(ItemFields.AirTime)) if (options.GetImageLimit(ImageType.Primary) > 0)
{ {
dto.AirTime = episodeSeries.AirTime; episodeSeries = episodeSeries ?? episode.Series;
} if (episodeSeries != null)
if (options.GetImageLimit(ImageType.Thumb) > 0)
{
dto.SeriesThumbImageTag = GetImageCacheTag(episodeSeries, ImageType.Thumb);
}
if (options.GetImageLimit(ImageType.Primary) > 0)
{ {
dto.SeriesPrimaryImageTag = GetImageCacheTag(episodeSeries, ImageType.Primary); dto.SeriesPrimaryImageTag = GetImageCacheTag(episodeSeries, ImageType.Primary);
} }
}
if (fields.Contains(ItemFields.SeriesStudio)) if (fields.Contains(ItemFields.SeriesStudio))
{
episodeSeries = episodeSeries ?? episode.Series;
if (episodeSeries != null)
{ {
dto.SeriesStudio = episodeSeries.Studios.FirstOrDefault(); dto.SeriesStudio = episodeSeries.Studios.FirstOrDefault();
} }
@ -1475,7 +1374,6 @@ namespace MediaBrowser.Server.Implementations.Dto
if (series != null) if (series != null)
{ {
dto.SeriesId = GetDtoId(series); dto.SeriesId = GetDtoId(series);
dto.AirTime = series.AirTime;
if (fields.Contains(ItemFields.SeriesStudio)) if (fields.Contains(ItemFields.SeriesStudio))
{ {
@ -1533,6 +1431,70 @@ namespace MediaBrowser.Server.Implementations.Dto
} }
} }
private void AddInheritedImages(BaseItemDto dto, BaseItem item, DtoOptions options, BaseItem owner)
{
var logoLimit = options.GetImageLimit(ImageType.Logo);
var artLimit = options.GetImageLimit(ImageType.Art);
var thumbLimit = options.GetImageLimit(ImageType.Thumb);
var backdropLimit = options.GetImageLimit(ImageType.Backdrop);
if (logoLimit == 0 && artLimit == 0 && thumbLimit == 0 && backdropLimit == 0)
{
return;
}
BaseItem parent = null;
var isFirst = true;
while (((!dto.HasLogo && logoLimit > 0) || (!dto.HasArtImage && artLimit > 0) || (!dto.HasThumb && thumbLimit > 0) || parent is Series) &&
(parent = parent ?? (isFirst ? item.GetParent() ?? owner : parent)) != null)
{
if (logoLimit > 0 && !dto.HasLogo && dto.ParentLogoItemId == null)
{
var image = parent.GetImageInfo(ImageType.Logo, 0);
if (image != null)
{
dto.ParentLogoItemId = GetDtoId(parent);
dto.ParentLogoImageTag = GetImageCacheTag(parent, image);
}
}
if (artLimit > 0 && !dto.HasArtImage && dto.ParentArtItemId == null)
{
var image = parent.GetImageInfo(ImageType.Art, 0);
if (image != null)
{
dto.ParentArtItemId = GetDtoId(parent);
dto.ParentArtImageTag = GetImageCacheTag(parent, image);
}
}
if (thumbLimit > 0 && !dto.HasThumb && (dto.ParentThumbItemId == null || parent is Series))
{
var image = parent.GetImageInfo(ImageType.Thumb, 0);
if (image != null)
{
dto.ParentThumbItemId = GetDtoId(parent);
dto.ParentThumbImageTag = GetImageCacheTag(parent, image);
}
}
if (backdropLimit > 0 && !dto.HasBackdrop)
{
var images = parent.GetImages(ImageType.Backdrop).Take(backdropLimit).ToList();
if (images.Count > 0)
{
dto.ParentBackdropItemId = GetDtoId(parent);
dto.ParentBackdropImageTags = GetImageTags(parent, images);
}
}
isFirst = false;
parent = parent.GetParent();
}
}
private string GetMappedPath(IHasMetadata item) private string GetMappedPath(IHasMetadata item)
{ {
var path = item.Path; var path = item.Path;

View File

@ -368,10 +368,10 @@ namespace MediaBrowser.Server.Implementations.Library
{ {
return; return;
} }
//if (!(item is Folder)) if (!(item is Folder))
//{ {
// return; return;
//} }
LibraryItemsCache.AddOrUpdate(id, item, delegate { return item; }); LibraryItemsCache.AddOrUpdate(id, item, delegate { return item; });
} }

View File

@ -45,6 +45,14 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
{ {
var episode = ResolveVideo<Episode>(args, false); var episode = ResolveVideo<Episode>(args, false);
if (episode != null)
{
if (season != null)
{
episode.SeasonId = season.Id;
}
}
return episode; return episode;
} }

View File

@ -1214,8 +1214,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv
var item = await GetChannel(channelInfo.Item2, channelInfo.Item1, parentFolderId, cancellationToken).ConfigureAwait(false); var item = await GetChannel(channelInfo.Item2, channelInfo.Item1, parentFolderId, cancellationToken).ConfigureAwait(false);
list.Add(item); list.Add(item);
_libraryManager.RegisterItem(item);
} }
catch (OperationCanceledException) catch (OperationCanceledException)
{ {

View File

@ -95,7 +95,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
private IDbCommand _updateInheritedRatingCommand; private IDbCommand _updateInheritedRatingCommand;
private IDbCommand _updateInheritedTagsCommand; private IDbCommand _updateInheritedTagsCommand;
public const int LatestSchemaVersion = 99; public const int LatestSchemaVersion = 100;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class. /// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
@ -272,6 +272,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
_connection.AddColumn(Logger, "TypedBaseItems", "SeriesName", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "SeriesName", "Text");
_connection.AddColumn(Logger, "TypedBaseItems", "UserDataKey", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "UserDataKey", "Text");
_connection.AddColumn(Logger, "TypedBaseItems", "SeasonName", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "SeasonName", "Text");
_connection.AddColumn(Logger, "TypedBaseItems", "SeasonId", "GUID");
_connection.AddColumn(Logger, "UserDataKeys", "Priority", "INT"); _connection.AddColumn(Logger, "UserDataKeys", "Priority", "INT");
_connection.AddColumn(Logger, "ItemValues", "CleanValue", "Text"); _connection.AddColumn(Logger, "ItemValues", "CleanValue", "Text");
@ -405,7 +406,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
"CriticRatingSummary", "CriticRatingSummary",
"IsVirtualItem", "IsVirtualItem",
"SeriesName", "SeriesName",
"SeasonName" "SeasonName",
"SeasonId"
}; };
private readonly string[] _mediaStreamSaveColumns = private readonly string[] _mediaStreamSaveColumns =
@ -526,7 +528,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
"IsVirtualItem", "IsVirtualItem",
"SeriesName", "SeriesName",
"UserDataKey", "UserDataKey",
"SeasonName" "SeasonName",
"SeasonId"
}; };
_saveItemCommand = _connection.CreateCommand(); _saveItemCommand = _connection.CreateCommand();
_saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values ("; _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values (";
@ -961,10 +964,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
if (episode != null) if (episode != null)
{ {
_saveItemCommand.GetParameter(index++).Value = episode.FindSeasonName(); _saveItemCommand.GetParameter(index++).Value = episode.FindSeasonName();
_saveItemCommand.GetParameter(index++).Value = episode.FindSeasonId();
} }
else else
{ {
_saveItemCommand.GetParameter(index++).Value = null; _saveItemCommand.GetParameter(index++).Value = null;
_saveItemCommand.GetParameter(index++).Value = null;
} }
_saveItemCommand.Transaction = transaction; _saveItemCommand.Transaction = transaction;
@ -1405,6 +1410,10 @@ namespace MediaBrowser.Server.Implementations.Persistence
{ {
episode.SeasonName = reader.GetString(60); episode.SeasonName = reader.GetString(60);
} }
if (!reader.IsDBNull(61))
{
episode.SeasonId = reader.GetGuid(61);
}
} }
return item; return item;

View File

@ -54,11 +54,6 @@ namespace MediaBrowser.Server.Implementations.UserViews
{ {
return series; return series;
} }
var episodeSeason = episode.Season;
if (episodeSeason != null)
{
return episodeSeason;
}
return episode; return episode;
} }

View File

@ -86,11 +86,6 @@ namespace MediaBrowser.Server.Implementations.UserViews
{ {
return series; return series;
} }
var episodeSeason = episode.Season;
if (episodeSeason != null)
{
return episodeSeason;
}
return episode; return episode;
} }