denormalize seasonid

pull/702/head
Luke Pulverenti 8 years ago
parent 73e2b1f283
commit 2772d59559

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

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

@ -954,6 +954,16 @@ namespace MediaBrowser.Model.Dto
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>
/// Gets a value indicating whether this instance has primary image.
/// </summary>

@ -429,7 +429,8 @@ namespace MediaBrowser.Providers.TV
IndexNumber = episodeNumber,
ParentIndexNumber = seasonNumber,
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);

@ -663,19 +663,12 @@ namespace MediaBrowser.Server.Implementations.Dto
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();
}
private List<string> GetScreenshotImageTags(BaseItem item, int limit)
{
var hasScreenshots = item as IHasScreenshots;
if (hasScreenshots == null)
{
return new List<string>();
}
return GetCacheTags(item, ImageType.Screenshot, limit).ToList();
return images
.Select(p => GetImageCacheTag(item, p))
.Where(i => i != null)
.ToList();
}
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>
/// Gets the chapter info dto.
/// </summary>
@ -1027,7 +973,7 @@ namespace MediaBrowser.Server.Implementations.Dto
var backdropLimit = options.GetImageLimit(ImageType.Backdrop);
if (backdropLimit > 0)
{
dto.BackdropImageTags = GetBackdropImageTags(item, backdropLimit);
dto.BackdropImageTags = GetImageTags(item, item.GetImages(ImageType.Backdrop).Take(backdropLimit).ToList());
}
if (fields.Contains(ItemFields.ScreenshotImageTags))
@ -1035,7 +981,7 @@ namespace MediaBrowser.Server.Implementations.Dto
var screenshotLimit = options.GetImageLimit(ImageType.Screenshot);
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.IndexNumber = item.IndexNumber;
dto.ParentIndexNumber = item.ParentIndexNumber;
dto.IsFolder = item.IsFolder;
dto.MediaType = item.MediaType;
dto.LocationType = item.LocationType;
@ -1126,18 +1073,6 @@ namespace MediaBrowser.Server.Implementations.Dto
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))
{
var displayParentId = item.DisplayParentId;
@ -1147,46 +1082,7 @@ namespace MediaBrowser.Server.Implementations.Dto
}
}
dto.ParentIndexNumber = item.ParentIndexNumber;
// 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);
}
}
AddInheritedImages(dto, item, options, owner);
if (fields.Contains(ItemFields.Path))
{
@ -1420,33 +1316,36 @@ namespace MediaBrowser.Server.Implementations.Dto
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();
}
}
episodeSeries = episodeSeries ?? episode.Series;
if (episodeSeries != null)
{
dto.SeriesId = GetDtoId(episodeSeries);
}
if (fields.Contains(ItemFields.AirTime))
{
dto.AirTime = episodeSeries.AirTime;
}
if (options.GetImageLimit(ImageType.Thumb) > 0)
{
dto.SeriesThumbImageTag = GetImageCacheTag(episodeSeries, ImageType.Thumb);
}
if (options.GetImageLimit(ImageType.Primary) > 0)
if (options.GetImageLimit(ImageType.Primary) > 0)
{
episodeSeries = episodeSeries ?? episode.Series;
if (episodeSeries != null)
{
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();
}
@ -1475,7 +1374,6 @@ namespace MediaBrowser.Server.Implementations.Dto
if (series != null)
{
dto.SeriesId = GetDtoId(series);
dto.AirTime = series.AirTime;
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)
{
var path = item.Path;

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

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

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

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

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

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

Loading…
Cancel
Save