From f952ac0f1f84f43f68cd28173b7c3ff9369a2040 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 7 Jul 2016 23:22:02 -0400 Subject: [PATCH] fix season ids --- MediaBrowser.Controller/Entities/Book.cs | 1 + .../Entities/TV/Episode.cs | 1 + MediaBrowser.Controller/Entities/TV/Season.cs | 1 + .../Dto/DtoService.cs | 26 +++++----- .../Persistence/CleanDatabaseScheduledTask.cs | 49 ++++++++++++++----- 5 files changed, 51 insertions(+), 27 deletions(-) diff --git a/MediaBrowser.Controller/Entities/Book.cs b/MediaBrowser.Controller/Entities/Book.cs index 34368d61f..9d35c86d2 100644 --- a/MediaBrowser.Controller/Entities/Book.cs +++ b/MediaBrowser.Controller/Entities/Book.cs @@ -20,6 +20,7 @@ namespace MediaBrowser.Controller.Entities [IgnoreDataMember] public string SeriesName { get; set; } + [IgnoreDataMember] public Guid? SeriesId { get; set; } public string FindSeriesName() diff --git a/MediaBrowser.Controller/Entities/TV/Episode.cs b/MediaBrowser.Controller/Entities/TV/Episode.cs index b13c291d1..78c35ad48 100644 --- a/MediaBrowser.Controller/Entities/TV/Episode.cs +++ b/MediaBrowser.Controller/Entities/TV/Episode.cs @@ -249,6 +249,7 @@ namespace MediaBrowser.Controller.Entities.TV [IgnoreDataMember] public Guid? SeasonId { get; set; } + [IgnoreDataMember] public Guid? SeriesId { get; set; } public Guid? FindSeriesId() diff --git a/MediaBrowser.Controller/Entities/TV/Season.cs b/MediaBrowser.Controller/Entities/TV/Season.cs index 218d0fef8..865cadeb9 100644 --- a/MediaBrowser.Controller/Entities/TV/Season.cs +++ b/MediaBrowser.Controller/Entities/TV/Season.cs @@ -237,6 +237,7 @@ namespace MediaBrowser.Controller.Entities.TV [IgnoreDataMember] public string SeriesName { get; set; } + [IgnoreDataMember] public Guid? SeriesId { get; set; } public string FindSeriesName() diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 3e009d210..de6c23cac 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -671,17 +671,6 @@ namespace MediaBrowser.Server.Implementations.Dto .ToList(); } - private IEnumerable GetCacheTags(BaseItem item, ImageType type, int limit) - { - return item.GetImages(type) - // Convert to a list now in case GetImageCacheTag is slow - .ToList() - .Select(p => GetImageCacheTag(item, p)) - .Where(i => i != null) - .Take(limit) - .ToList(); - } - private string GetImageCacheTag(BaseItem item, ImageType type) { try @@ -1458,9 +1447,16 @@ namespace MediaBrowser.Server.Implementations.Dto 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 (parent == null) + { + break; + } + + var allImages = parent.ImageInfos; + if (logoLimit > 0 && !dto.HasLogo && dto.ParentLogoItemId == null) { - var image = parent.GetImageInfo(ImageType.Logo, 0); + var image = allImages.FirstOrDefault(i => i.Type == ImageType.Logo); if (image != null) { @@ -1470,7 +1466,7 @@ namespace MediaBrowser.Server.Implementations.Dto } if (artLimit > 0 && !dto.HasArtImage && dto.ParentArtItemId == null) { - var image = parent.GetImageInfo(ImageType.Art, 0); + var image = allImages.FirstOrDefault(i => i.Type == ImageType.Art); if (image != null) { @@ -1480,7 +1476,7 @@ namespace MediaBrowser.Server.Implementations.Dto } if (thumbLimit > 0 && !dto.HasThumb && (dto.ParentThumbItemId == null || parent is Series)) { - var image = parent.GetImageInfo(ImageType.Thumb, 0); + var image = allImages.FirstOrDefault(i => i.Type == ImageType.Thumb); if (image != null) { @@ -1490,7 +1486,7 @@ namespace MediaBrowser.Server.Implementations.Dto } if (backdropLimit > 0 && !dto.HasBackdrop) { - var images = parent.GetImages(ImageType.Backdrop).Take(backdropLimit).ToList(); + var images = allImages.Where(i => i.Type == ImageType.Backdrop).Take(backdropLimit).ToList(); if (images.Count > 0) { diff --git a/MediaBrowser.Server.Implementations/Persistence/CleanDatabaseScheduledTask.cs b/MediaBrowser.Server.Implementations/Persistence/CleanDatabaseScheduledTask.cs index b11a3e496..bf2afb5ac 100644 --- a/MediaBrowser.Server.Implementations/Persistence/CleanDatabaseScheduledTask.cs +++ b/MediaBrowser.Server.Implementations/Persistence/CleanDatabaseScheduledTask.cs @@ -155,6 +155,8 @@ namespace MediaBrowser.Server.Implementations.Persistence _logger.Debug("Upgrading schema for {0} items", numItems); + var list = new List(); + foreach (var itemId in itemIds) { cancellationToken.ThrowIfCancellationRequested(); @@ -166,27 +168,50 @@ namespace MediaBrowser.Server.Implementations.Persistence if (item != null) { - try - { - await _itemRepo.SaveItem(item, cancellationToken).ConfigureAwait(false); - } - catch (OperationCanceledException) - { - throw; - } - catch (Exception ex) - { - _logger.ErrorException("Error saving item", ex); - } + list.Add(item); } } + if (list.Count >= 1000) + { + try + { + await _itemRepo.SaveItems(list, cancellationToken).ConfigureAwait(false); + } + catch (OperationCanceledException) + { + throw; + } + catch (Exception ex) + { + _logger.ErrorException("Error saving item", ex); + } + + list.Clear(); + } + numComplete++; double percent = numComplete; percent /= numItems; progress.Report(percent * 100); } + if (list.Count > 0) + { + try + { + await _itemRepo.SaveItems(list, cancellationToken).ConfigureAwait(false); + } + catch (OperationCanceledException) + { + throw; + } + catch (Exception ex) + { + _logger.ErrorException("Error saving item", ex); + } + } + progress.Report(100); }