From a0dfbdfd70fe85fca64b341b6fe30708e9a9ebe9 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 8 May 2013 14:12:55 -0400 Subject: [PATCH 1/2] Add file lock logging message --- MediaBrowser.Server.Implementations/IO/DirectoryWatchers.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MediaBrowser.Server.Implementations/IO/DirectoryWatchers.cs b/MediaBrowser.Server.Implementations/IO/DirectoryWatchers.cs index beeb1c181..b9b2b560b 100644 --- a/MediaBrowser.Server.Implementations/IO/DirectoryWatchers.cs +++ b/MediaBrowser.Server.Implementations/IO/DirectoryWatchers.cs @@ -23,7 +23,7 @@ namespace MediaBrowser.Server.Implementations.IO /// /// The file system watchers /// - private ConcurrentDictionary _fileSystemWatchers = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + private readonly ConcurrentDictionary _fileSystemWatchers = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); /// /// The update timer /// @@ -424,6 +424,7 @@ namespace MediaBrowser.Server.Implementations.IO //still being written to //or being processed by another thread //or does not exist (has already been processed) + Logger.Debug("{0} is locked.", path); return true; } } From fbd052abfc2724fcb151582746c9783d7ab8a97a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 8 May 2013 16:58:52 -0400 Subject: [PATCH 2/2] removed local trailers and special features from memory --- .../Progressive/ProgressiveStreamWriter.cs | 2 +- MediaBrowser.Api/UserLibrary/ItemsService.cs | 14 +- .../UserLibrary/UserLibraryService.cs | 14 +- .../BaseApplicationHost.cs | 4 - .../HttpClientManager/HttpClientManager.cs | 2 +- MediaBrowser.Controller/Dto/DtoBuilder.cs | 4 +- MediaBrowser.Controller/Entities/BaseItem.cs | 162 +++++++----------- .../Entities/Movies/Movie.cs | 72 +++----- .../Persistence/IItemRepository.cs | 9 +- .../Providers/Music/LastfmArtistProvider.cs | 16 +- .../Providers/TV/RemoteEpisodeProvider.cs | 1 - .../Providers/TV/RemoteSeasonProvider.cs | 1 - .../Providers/TV/RemoteSeriesProvider.cs | 1 - .../Library/LibraryManager.cs | 55 +----- .../ScheduledTasks/ImageCleanupTask.cs | 28 ++- .../ScheduledTasks/VideoImagesTask.cs | 15 +- .../SQLiteDisplayPreferencesRepository.cs | 44 ++--- .../Sqlite/SQLiteItemRepository.cs | 103 ++++++----- .../Sqlite/SQLiteRepository.cs | 16 +- .../Sqlite/SQLiteUserDataRepository.cs | 76 ++++---- .../Sqlite/SQLiteUserRepository.cs | 72 ++++---- .../LibraryExplorer.xaml.cs | 13 +- 22 files changed, 331 insertions(+), 393 deletions(-) diff --git a/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs b/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs index 85ac018f6..6eb3eb643 100644 --- a/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs +++ b/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs @@ -96,7 +96,7 @@ namespace MediaBrowser.Api.Playback.Progressive var bytesRead = fsPosition - position; - Logger.Debug("Streamed {0} bytes from file {1}", bytesRead, path); + //Logger.Debug("Streamed {0} bytes from file {1}", bytesRead, path); if (bytesRead == 0) { diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index af4f94f50..f33c51c5c 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -547,22 +547,22 @@ namespace MediaBrowser.Api.UserLibrary if (request.HasTrailer.HasValue) { - items = items.Where(i => request.HasTrailer.Value ? i.LocalTrailers.Count > 0 : i.LocalTrailers.Count == 0); + items = items.Where(i => request.HasTrailer.Value ? i.LocalTrailerIds.Count > 0 : i.LocalTrailerIds.Count == 0); } if (request.HasThemeSong.HasValue) { - items = items.Where(i => request.HasThemeSong.Value ? i.ThemeSongs.Count > 0 : i.ThemeSongs.Count == 0); + items = items.Where(i => request.HasThemeSong.Value ? i.ThemeSongIds.Count > 0 : i.ThemeSongIds.Count == 0); } if (request.HasThemeVideo.HasValue) { - items = items.Where(i => request.HasThemeVideo.Value ? i.ThemeVideos.Count > 0 : i.ThemeVideos.Count == 0); + items = items.Where(i => request.HasThemeVideo.Value ? i.ThemeVideoIds.Count > 0 : i.ThemeVideoIds.Count == 0); } if (request.HasSpecialFeature.HasValue) { - items = items.OfType().Where(i => request.HasSpecialFeature.Value ? i.SpecialFeatures.Count > 0 : i.SpecialFeatures.Count == 0); + items = items.OfType().Where(i => request.HasSpecialFeature.Value ? i.SpecialFeatureIds.Count > 0 : i.SpecialFeatureIds.Count == 0); } if (request.HasSubtitles.HasValue) @@ -573,10 +573,8 @@ namespace MediaBrowser.Api.UserLibrary { return i.MediaStreams != null && i.MediaStreams.Any(m => m.Type == MediaStreamType.Subtitle); } - else - { - return i.MediaStreams == null || i.MediaStreams.All(m => m.Type != MediaStreamType.Subtitle); - } + + return i.MediaStreams == null || i.MediaStreams.All(m => m.Type != MediaStreamType.Subtitle); }); } diff --git a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs index 9d809f888..5c1eff954 100644 --- a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs +++ b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs @@ -399,19 +399,23 @@ namespace MediaBrowser.Api.UserLibrary /// private readonly ILibraryManager _libraryManager; + private readonly IItemRepository _itemRepo; + /// /// Initializes a new instance of the class. /// /// The user manager. /// The library manager. /// The user data repository. + /// The item repo. /// jsonSerializer - public UserLibraryService(IUserManager userManager, ILibraryManager libraryManager, IUserDataRepository userDataRepository) + public UserLibraryService(IUserManager userManager, ILibraryManager libraryManager, IUserDataRepository userDataRepository, IItemRepository itemRepo) : base() { _userManager = userManager; _libraryManager = libraryManager; _userDataRepository = userDataRepository; + _itemRepo = itemRepo; } /// @@ -432,7 +436,7 @@ namespace MediaBrowser.Api.UserLibrary var dtoBuilder = new DtoBuilder(Logger, _libraryManager, _userDataRepository); - var items = movie.SpecialFeatures.OrderBy(i => i.SortName).Select(i => dtoBuilder.GetBaseItemDto(i, user, fields)).Select(t => t.Result).ToList(); + var items = _itemRepo.GetItems(movie.SpecialFeatureIds).OrderBy(i => i.SortName).Select(i => dtoBuilder.GetBaseItemDto(i, user, fields)).Select(t => t.Result).ToList(); return ToOptimizedResult(items); } @@ -453,7 +457,7 @@ namespace MediaBrowser.Api.UserLibrary var dtoBuilder = new DtoBuilder(Logger, _libraryManager, _userDataRepository); - var items = item.LocalTrailers.OrderBy(i => i.SortName).Select(i => dtoBuilder.GetBaseItemDto(i, user, fields)).Select(t => t.Result).ToList(); + var items = _itemRepo.GetItems(item.LocalTrailerIds).OrderBy(i => i.SortName).Select(i => dtoBuilder.GetBaseItemDto(i, user, fields)).Select(t => t.Result).ToList(); return ToOptimizedResult(items); } @@ -474,7 +478,7 @@ namespace MediaBrowser.Api.UserLibrary var dtoBuilder = new DtoBuilder(Logger, _libraryManager, _userDataRepository); - var items = item.ThemeSongs.OrderBy(i => i.SortName).Select(i => dtoBuilder.GetBaseItemDto(i, user, fields)).Select(t => t.Result).ToArray(); + var items = _itemRepo.GetItems(item.ThemeSongIds).OrderBy(i => i.SortName).Select(i => dtoBuilder.GetBaseItemDto(i, user, fields)).Select(t => t.Result).ToArray(); var result = new ThemeSongsResult { @@ -502,7 +506,7 @@ namespace MediaBrowser.Api.UserLibrary var dtoBuilder = new DtoBuilder(Logger, _libraryManager, _userDataRepository); - var items = item.ThemeVideos.OrderBy(i => i.SortName).Select(i => dtoBuilder.GetBaseItemDto(i, user, fields)).Select(t => t.Result).ToArray(); + var items = _itemRepo.GetItems(item.ThemeVideoIds).OrderBy(i => i.SortName).Select(i => dtoBuilder.GetBaseItemDto(i, user, fields)).Select(t => t.Result).ToArray(); var result = new ThemeVideosResult { diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index 386da0ffa..34bdda94f 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -340,8 +340,6 @@ namespace MediaBrowser.Common.Implementations protected void RegisterSingleInstance(T obj, bool manageLifetime = true) where T : class { - Logger.Info("Registering " + obj.GetType().Name); - Container.RegisterSingle(obj); if (manageLifetime) @@ -421,8 +419,6 @@ namespace MediaBrowser.Common.Implementations { var currentType = typeof(T); - Logger.Info("Composing instances of " + currentType.Name); - var parts = AllConcreteTypes.AsParallel().Where(currentType.IsAssignableFrom).Select(CreateInstance).Cast().ToArray(); if (manageLiftime) diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs index 23433ac75..4c51d1299 100644 --- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -136,7 +136,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager { var now = DateTime.UtcNow; - var isCacheValid = (!cachedInfo.MustRevalidate && !string.IsNullOrEmpty(cachedInfo.Etag) && (now - cachedInfo.RequestDate).TotalDays < 14) + var isCacheValid = (!cachedInfo.MustRevalidate && !string.IsNullOrEmpty(cachedInfo.Etag) && (now - cachedInfo.RequestDate).TotalDays < 7) || (cachedInfo.Expires.HasValue && cachedInfo.Expires.Value > now); if (isCacheValid) diff --git a/MediaBrowser.Controller/Dto/DtoBuilder.cs b/MediaBrowser.Controller/Dto/DtoBuilder.cs index e16fb6d94..d84227059 100644 --- a/MediaBrowser.Controller/Dto/DtoBuilder.cs +++ b/MediaBrowser.Controller/Dto/DtoBuilder.cs @@ -331,7 +331,7 @@ namespace MediaBrowser.Controller.Dto dto.CriticRatingSummary = item.CriticRatingSummary; } - var localTrailerCount = item.LocalTrailers == null ? 0 : item.LocalTrailers.Count; + var localTrailerCount = item.LocalTrailerIds.Count; if (localTrailerCount > 0) { @@ -492,7 +492,7 @@ namespace MediaBrowser.Controller.Dto if (movie != null) { - var specialFeatureCount = movie.SpecialFeatures == null ? 0 : movie.SpecialFeatures.Count; + var specialFeatureCount = movie.SpecialFeatureIds.Count; if (specialFeatureCount > 0) { diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index d7fc1cc8e..e31939d59 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -38,6 +38,9 @@ namespace MediaBrowser.Controller.Entities Images = new Dictionary(); ProviderIds = new Dictionary(StringComparer.OrdinalIgnoreCase); Tags = new List(); + ThemeSongIds = new List(); + ThemeVideoIds = new List(); + LocalTrailerIds = new List(); } /// @@ -572,7 +575,7 @@ namespace MediaBrowser.Controller.Entities /// /// The tags. public List Tags { get; set; } - + /// /// Override this if you need to combine/collapse person information /// @@ -612,7 +615,7 @@ namespace MediaBrowser.Controller.Entities /// /// The revenue. public double? Revenue { get; set; } - + /// /// Gets or sets the production locations. /// @@ -630,7 +633,7 @@ namespace MediaBrowser.Controller.Entities /// /// The critic rating summary. public string CriticRatingSummary { get; set; } - + /// /// Gets or sets the community rating. /// @@ -672,84 +675,9 @@ namespace MediaBrowser.Controller.Entities /// The critic reviews. public List CriticReviews { get; set; } - /// - /// The _local trailers - /// - private List _localTrailers; - /// - /// The _local trailers initialized - /// - private bool _localTrailersInitialized; - /// - /// The _local trailers sync lock - /// - private object _localTrailersSyncLock = new object(); - /// - /// Gets the local trailers. - /// - /// The local trailers. - [IgnoreDataMember] - public List LocalTrailers - { - get - { - LazyInitializer.EnsureInitialized(ref _localTrailers, ref _localTrailersInitialized, ref _localTrailersSyncLock, LoadLocalTrailers); - return _localTrailers; - } - private set - { - _localTrailers = value; - - if (value == null) - { - _localTrailersInitialized = false; - } - } - } - - private List _themeSongs; - private bool _themeSongsInitialized; - private object _themeSongsSyncLock = new object(); - [IgnoreDataMember] - public List ThemeSongs - { - get - { - LazyInitializer.EnsureInitialized(ref _themeSongs, ref _themeSongsInitialized, ref _themeSongsSyncLock, LoadThemeSongs); - return _themeSongs; - } - private set - { - _themeSongs = value; - - if (value == null) - { - _themeSongsInitialized = false; - } - } - } - - private List