From bbaa0977fdeaa16f0d43bd043ebf794d1b7aec83 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 11 Nov 2016 23:02:22 -0500 Subject: [PATCH] cache now playing item --- .../Session/SessionManager.cs | 33 ++++++++++++++----- .../Session/SessionInfo.cs | 5 ++- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index 960fe07397..300b67ae2f 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -566,6 +566,23 @@ namespace Emby.Server.Implementations.Session } } + private BaseItem GetNowPlayingItem(SessionInfo session, string itemId) + { + var idGuid = new Guid(itemId); + + var item = session.FullNowPlayingItem; + if (item != null && item.Id == idGuid) + { + return item; + } + + item = _libraryManager.GetItemById(itemId); + + session.FullNowPlayingItem = item; + + return item; + } + /// /// Used to report that playback has started for an item /// @@ -583,7 +600,7 @@ namespace Emby.Server.Implementations.Session var libraryItem = string.IsNullOrWhiteSpace(info.ItemId) ? null - : _libraryManager.GetItemById(new Guid(info.ItemId)); + : GetNowPlayingItem(session, info.ItemId); await UpdateNowPlayingItem(session, info, libraryItem).ConfigureAwait(false); @@ -669,7 +686,7 @@ namespace Emby.Server.Implementations.Session var libraryItem = string.IsNullOrWhiteSpace(info.ItemId) ? null - : _libraryManager.GetItemById(new Guid(info.ItemId)); + : GetNowPlayingItem(session, info.ItemId); await UpdateNowPlayingItem(session, info, libraryItem).ConfigureAwait(false); @@ -773,7 +790,7 @@ namespace Emby.Server.Implementations.Session var libraryItem = string.IsNullOrWhiteSpace(info.ItemId) ? null - : _libraryManager.GetItemById(new Guid(info.ItemId)); + : GetNowPlayingItem(session, info.ItemId); // Normalize if (string.IsNullOrWhiteSpace(info.MediaSourceId)) @@ -1782,18 +1799,18 @@ namespace Emby.Server.Implementations.Session throw new ArgumentNullException("itemId"); } - var item = _libraryManager.GetItemById(new Guid(itemId)); + //var item = _libraryManager.GetItemById(new Guid(itemId)); - var info = GetItemInfo(item, null, null); + //var info = GetItemInfo(item, null, null); - ReportNowViewingItem(sessionId, info); + //ReportNowViewingItem(sessionId, info); } public void ReportNowViewingItem(string sessionId, BaseItemInfo item) { - var session = GetSession(sessionId); + //var session = GetSession(sessionId); - session.NowViewingItem = item; + //session.NowViewingItem = item; } public void ReportTranscodingInfo(string deviceId, TranscodingInfo info) diff --git a/MediaBrowser.Controller/Session/SessionInfo.cs b/MediaBrowser.Controller/Session/SessionInfo.cs index b3e82f9258..343b15a04f 100644 --- a/MediaBrowser.Controller/Session/SessionInfo.cs +++ b/MediaBrowser.Controller/Session/SessionInfo.cs @@ -3,6 +3,7 @@ using MediaBrowser.Model.Session; using System; using System.Collections.Generic; using System.Linq; +using MediaBrowser.Controller.Entities; namespace MediaBrowser.Controller.Session { @@ -106,7 +107,9 @@ namespace MediaBrowser.Controller.Session /// /// The now playing item. public BaseItemInfo NowPlayingItem { get; set; } - + + public BaseItem FullNowPlayingItem { get; set; } + /// /// Gets or sets the device id. ///