From ffbac0e3d80bcff2daf89bbf45514a742a75f78e Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Sat, 15 Sep 2012 16:32:41 -0400 Subject: [PATCH] Eliminated some list recursions --- .../MediaBrowser.Common.csproj | 2 +- MediaBrowser.Controller/Entities/Folder.cs | 71 +++++++++++++------ 2 files changed, 50 insertions(+), 23 deletions(-) diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index da01fde35..fca71ebd0 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -69,7 +69,7 @@ - + ..\packages\MahApps.Metro.0.9.0.0\lib\net40\System.Windows.Interactivity.dll diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 8d7fc4021..b9a72e727 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -65,9 +65,11 @@ namespace MediaBrowser.Controller.Entities IEnumerable recursiveChildren = GetParentalAllowedRecursiveChildren(user); - counts.RecentlyAddedItemCount = GetRecentlyAddedItems(recursiveChildren, user).Count(); - counts.RecentlyAddedUnPlayedItemCount = GetRecentlyAddedUnplayedItems(recursiveChildren, user).Count(); - counts.InProgressItemCount = GetInProgressItems(recursiveChildren, user).Count(); + var recentlyAddedItems = GetRecentlyAddedItems(recursiveChildren, user); + + counts.RecentlyAddedItemCount = recentlyAddedItems.Count; + counts.RecentlyAddedUnPlayedItemCount = GetRecentlyAddedUnplayedItems(recentlyAddedItems, user).Count; + counts.InProgressItemCount = GetInProgressItems(recursiveChildren, user).Count; counts.PlayedPercentage = GetPlayedPercentage(recursiveChildren, user); return counts; @@ -151,7 +153,7 @@ namespace MediaBrowser.Controller.Entities /// /// Gets all recently added items (recursive) within a folder, based on configuration and parental settings /// - public IEnumerable GetRecentlyAddedItems(User user) + public List GetRecentlyAddedItems(User user) { return GetRecentlyAddedItems(GetParentalAllowedRecursiveChildren(user), user); } @@ -159,7 +161,7 @@ namespace MediaBrowser.Controller.Entities /// /// Gets all recently added unplayed items (recursive) within a folder, based on configuration and parental settings /// - public IEnumerable GetRecentlyAddedUnplayedItems(User user) + public List GetRecentlyAddedUnplayedItems(User user) { return GetRecentlyAddedUnplayedItems(GetParentalAllowedRecursiveChildren(user), user); } @@ -167,7 +169,7 @@ namespace MediaBrowser.Controller.Entities /// /// Gets all in-progress items (recursive) within a folder /// - public IEnumerable GetInProgressItems(User user) + public List GetInProgressItems(User user) { return GetInProgressItems(GetParentalAllowedRecursiveChildren(user), user); } @@ -175,40 +177,65 @@ namespace MediaBrowser.Controller.Entities /// /// Takes a list of items and returns the ones that are recently added /// - private static IEnumerable GetRecentlyAddedItems(IEnumerable itemSet, User user) + private static List GetRecentlyAddedItems(IEnumerable itemSet, User user) { - return itemSet.Where(i => !(i.IsFolder) && i.IsRecentlyAdded(user)); + var list = new List(); + + foreach (var item in itemSet) + { + if (!item.IsFolder && item.IsRecentlyAdded(user)) + { + list.Add(item); + } + } + + return list; } /// /// Takes a list of items and returns the ones that are recently added and unplayed /// - private static IEnumerable GetRecentlyAddedUnplayedItems(IEnumerable itemSet, User user) + private static List GetRecentlyAddedUnplayedItems(IEnumerable itemSet, User user) { - return GetRecentlyAddedItems(itemSet, user).Where(i => - { - var userdata = i.GetUserData(user, false); + var list = new List(); - return userdata == null || userdata.PlayCount == 0; - }); + foreach (var item in itemSet) + { + if (!item.IsFolder && item.IsRecentlyAdded(user)) + { + var userdata = item.GetUserData(user, false); + + if (userdata == null || userdata.PlayCount == 0) + { + list.Add(item); + } + } + } + + return list; } /// /// Takes a list of items and returns the ones that are in progress /// - private static IEnumerable GetInProgressItems(IEnumerable itemSet, User user) + private static List GetInProgressItems(IEnumerable itemSet, User user) { - return itemSet.Where(i => + var list = new List(); + + foreach (var item in itemSet) { - if (i.IsFolder) + if (!item.IsFolder) { - return false; + var userdata = item.GetUserData(user, false); + + if (userdata != null && userdata.PlaybackPositionTicks > 0) + { + list.Add(item); + } } + } - var userdata = i.GetUserData(user, false); - - return userdata != null && userdata.PlaybackPositionTicks > 0; - }); + return list; } ///