From fbd052abfc2724fcb151582746c9783d7ab8a97a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 8 May 2013 16:58:52 -0400 Subject: removed local trailers and special features from memory --- .../Sqlite/SQLiteItemRepository.cs | 103 +++++++++++++-------- 1 file changed, 62 insertions(+), 41 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Sqlite/SQLiteItemRepository.cs') diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteItemRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteItemRepository.cs index a3d184888..9138baad0 100644 --- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteItemRepository.cs @@ -1,3 +1,4 @@ +using System.Linq; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Persistence; @@ -156,16 +157,32 @@ namespace MediaBrowser.Server.Implementations.Sqlite /// The id. /// BaseItem. /// - public BaseItem RetrieveItem(Guid id) + public BaseItem GetItem(Guid id) { if (id == Guid.Empty) { - throw new ArgumentException(); + throw new ArgumentNullException("id"); } return RetrieveItemInternal(id); } + /// + /// Retrieves the items. + /// + /// The ids. + /// IEnumerable{BaseItem}. + /// ids + public IEnumerable GetItems(IEnumerable ids) + { + if (ids == null) + { + throw new ArgumentNullException("ids"); + } + + return ids.Select(RetrieveItemInternal); + } + /// /// Internal retrieve from items or users table /// @@ -176,35 +193,37 @@ namespace MediaBrowser.Server.Implementations.Sqlite { if (id == Guid.Empty) { - throw new ArgumentException(); + throw new ArgumentNullException("id"); } - var cmd = connection.CreateCommand(); - cmd.CommandText = "select obj_type,data from items where guid = @guid"; - var guidParam = cmd.Parameters.Add("@guid", DbType.Guid); - guidParam.Value = id; - - using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult | CommandBehavior.SingleRow)) + using (var cmd = connection.CreateCommand()) { - if (reader.Read()) + cmd.CommandText = "select obj_type,data from items where guid = @guid"; + var guidParam = cmd.Parameters.Add("@guid", DbType.Guid); + guidParam.Value = id; + + using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult | CommandBehavior.SingleRow)) { - var type = reader.GetString(0); - using (var stream = GetStream(reader, 1)) + if (reader.Read()) { - var itemType = _typeMapper.GetType(type); - - if (itemType == null) + var type = reader.GetString(0); + using (var stream = GetStream(reader, 1)) { - Logger.Error("Cannot find type {0}. Probably belongs to plug-in that is no longer loaded.", type); - return null; - } + var itemType = _typeMapper.GetType(type); - var item = _jsonSerializer.DeserializeFromStream(stream, itemType); - return item as BaseItem; + if (itemType == null) + { + Logger.Error("Cannot find type {0}. Probably belongs to plug-in that is no longer loaded.", type); + return null; + } + + var item = _jsonSerializer.DeserializeFromStream(stream, itemType); + return item as BaseItem; + } } } + return null; } - return null; } /// @@ -220,30 +239,32 @@ namespace MediaBrowser.Server.Implementations.Sqlite throw new ArgumentNullException(); } - var cmd = connection.CreateCommand(); - cmd.CommandText = "select obj_type,data from items where guid in (select child from children where guid = @guid)"; - var guidParam = cmd.Parameters.Add("@guid", DbType.Guid); - guidParam.Value = parent.Id; - - using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult)) + using (var cmd = connection.CreateCommand()) { - while (reader.Read()) - { - var type = reader.GetString(0); + cmd.CommandText = "select obj_type,data from items where guid in (select child from children where guid = @guid)"; + var guidParam = cmd.Parameters.Add("@guid", DbType.Guid); + guidParam.Value = parent.Id; - using (var stream = GetStream(reader, 1)) + using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult)) + { + while (reader.Read()) { - var itemType = _typeMapper.GetType(type); - if (itemType == null) - { - Logger.Error("Cannot find type {0}. Probably belongs to plug-in that is no longer loaded.", type); - continue; - } - var item = _jsonSerializer.DeserializeFromStream(stream, itemType) as BaseItem; - if (item != null) + var type = reader.GetString(0); + + using (var stream = GetStream(reader, 1)) { - item.Parent = parent; - yield return item; + var itemType = _typeMapper.GetType(type); + if (itemType == null) + { + Logger.Error("Cannot find type {0}. Probably belongs to plug-in that is no longer loaded.", type); + continue; + } + var item = _jsonSerializer.DeserializeFromStream(stream, itemType) as BaseItem; + if (item != null) + { + item.Parent = parent; + yield return item; + } } } } -- cgit v1.2.3