restore changes
This commit is contained in:
parent
d10aef45ea
commit
1851bda625
|
@ -19,6 +19,7 @@ using System.Runtime.Serialization;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Controller.Channels;
|
using MediaBrowser.Controller.Channels;
|
||||||
|
using MediaBrowser.Model.LiveTv;
|
||||||
|
|
||||||
namespace MediaBrowser.Server.Implementations.Persistence
|
namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
{
|
{
|
||||||
|
@ -76,7 +77,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
private IDbCommand _deleteStreamsCommand;
|
private IDbCommand _deleteStreamsCommand;
|
||||||
private IDbCommand _saveStreamCommand;
|
private IDbCommand _saveStreamCommand;
|
||||||
|
|
||||||
private const int LatestSchemaVersion = 13;
|
private IDbCommand _deleteAncestorsCommand;
|
||||||
|
private IDbCommand _saveAncestorCommand;
|
||||||
|
|
||||||
|
private IDbCommand _updateInheritedRatingCommand;
|
||||||
|
|
||||||
|
private const int LatestSchemaVersion = 40;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
|
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
|
||||||
|
@ -121,17 +127,24 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
_connection = await SqliteExtensions.ConnectToDb(dbFile, _logger).ConfigureAwait(false);
|
_connection = await SqliteExtensions.ConnectToDb(dbFile, _logger).ConfigureAwait(false);
|
||||||
|
|
||||||
var createMediaStreamsTableCommand
|
var createMediaStreamsTableCommand
|
||||||
= "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, IsCabac BIT NULL, KeyFrames TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))";
|
= "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, IsCabac BIT NULL, CodecTag TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))";
|
||||||
|
|
||||||
string[] queries = {
|
string[] queries = {
|
||||||
|
|
||||||
"create table if not exists TypedBaseItems (guid GUID primary key, type TEXT, data BLOB)",
|
"create table if not exists TypedBaseItems (guid GUID primary key, type TEXT, data BLOB, ParentId GUID)",
|
||||||
"create index if not exists idx_TypedBaseItems on TypedBaseItems(guid)",
|
"create index if not exists idx_TypedBaseItems on TypedBaseItems(guid)",
|
||||||
|
"create index if not exists idx_ParentIdTypedBaseItems on TypedBaseItems(ParentId)",
|
||||||
|
|
||||||
|
"create table if not exists AncestorIds (ItemId GUID, AncestorId GUID, AncestorIdText TEXT, PRIMARY KEY (ItemId, AncestorId))",
|
||||||
|
"create index if not exists idx_AncestorIds1 on AncestorIds(AncestorId)",
|
||||||
|
"create index if not exists idx_AncestorIds2 on AncestorIds(AncestorIdText)",
|
||||||
|
|
||||||
"create table if not exists ChildrenIds (ParentId GUID, ItemId GUID, PRIMARY KEY (ParentId, ItemId))",
|
"create table if not exists ChildrenIds (ParentId GUID, ItemId GUID, PRIMARY KEY (ParentId, ItemId))",
|
||||||
"create index if not exists idx_ChildrenIds on ChildrenIds(ParentId,ItemId)",
|
"create index if not exists idx_ChildrenIds on ChildrenIds(ParentId,ItemId)",
|
||||||
|
|
||||||
"create table if not exists People (ItemId GUID, Name TEXT NOT NULL, Role TEXT, PersonType TEXT, SortOrder int, ListOrder int)",
|
"create table if not exists People (ItemId GUID, Name TEXT NOT NULL, Role TEXT, PersonType TEXT, SortOrder int, ListOrder int)",
|
||||||
|
"create index if not exists idxPeopleItemId on People(ItemId)",
|
||||||
|
"create index if not exists idxPeopleName on People(Name)",
|
||||||
|
|
||||||
"create table if not exists "+ChaptersTableName+" (ItemId GUID, ChapterIndex INT, StartPositionTicks BIGINT, Name TEXT, ImagePath TEXT, PRIMARY KEY (ItemId, ChapterIndex))",
|
"create table if not exists "+ChaptersTableName+" (ItemId GUID, ChapterIndex INT, StartPositionTicks BIGINT, Name TEXT, ImagePath TEXT, PRIMARY KEY (ItemId, ChapterIndex))",
|
||||||
"create index if not exists idx_"+ChaptersTableName+" on "+ChaptersTableName+"(ItemId, ChapterIndex)",
|
"create index if not exists idx_"+ChaptersTableName+" on "+ChaptersTableName+"(ItemId, ChapterIndex)",
|
||||||
|
@ -147,6 +160,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
_connection.RunQueries(queries, _logger);
|
_connection.RunQueries(queries, _logger);
|
||||||
|
|
||||||
|
_connection.AddColumn(_logger, "AncestorIds", "AncestorIdText", "Text");
|
||||||
|
|
||||||
_connection.AddColumn(_logger, "TypedBaseItems", "Path", "Text");
|
_connection.AddColumn(_logger, "TypedBaseItems", "Path", "Text");
|
||||||
_connection.AddColumn(_logger, "TypedBaseItems", "StartDate", "DATETIME");
|
_connection.AddColumn(_logger, "TypedBaseItems", "StartDate", "DATETIME");
|
||||||
_connection.AddColumn(_logger, "TypedBaseItems", "EndDate", "DATETIME");
|
_connection.AddColumn(_logger, "TypedBaseItems", "EndDate", "DATETIME");
|
||||||
|
@ -198,6 +213,18 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
_connection.AddColumn(_logger, "TypedBaseItems", "ExternalEtag", "Text");
|
_connection.AddColumn(_logger, "TypedBaseItems", "ExternalEtag", "Text");
|
||||||
_connection.AddColumn(_logger, "TypedBaseItems", "DateLastRefreshed", "DATETIME");
|
_connection.AddColumn(_logger, "TypedBaseItems", "DateLastRefreshed", "DATETIME");
|
||||||
|
|
||||||
|
_connection.AddColumn(_logger, "TypedBaseItems", "DateLastSaved", "DATETIME");
|
||||||
|
_connection.AddColumn(_logger, "TypedBaseItems", "IsInMixedFolder", "BIT");
|
||||||
|
_connection.AddColumn(_logger, "TypedBaseItems", "LockedFields", "Text");
|
||||||
|
_connection.AddColumn(_logger, "TypedBaseItems", "Studios", "Text");
|
||||||
|
_connection.AddColumn(_logger, "TypedBaseItems", "Audio", "Text");
|
||||||
|
_connection.AddColumn(_logger, "TypedBaseItems", "ExternalServiceId", "Text");
|
||||||
|
_connection.AddColumn(_logger, "TypedBaseItems", "Tags", "Text");
|
||||||
|
_connection.AddColumn(_logger, "TypedBaseItems", "IsFolder", "BIT");
|
||||||
|
_connection.AddColumn(_logger, "TypedBaseItems", "InheritedParentalRatingValue", "INT");
|
||||||
|
_connection.AddColumn(_logger, "TypedBaseItems", "UnratedType", "Text");
|
||||||
|
_connection.AddColumn(_logger, "TypedBaseItems", "TopParentId", "Text");
|
||||||
|
|
||||||
PrepareStatements();
|
PrepareStatements();
|
||||||
|
|
||||||
new MediaStreamColumns(_connection, _logger).AddColumns();
|
new MediaStreamColumns(_connection, _logger).AddColumns();
|
||||||
|
@ -307,7 +334,27 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
"PreferredMetadataCountryCode",
|
"PreferredMetadataCountryCode",
|
||||||
"IsHD",
|
"IsHD",
|
||||||
"ExternalEtag",
|
"ExternalEtag",
|
||||||
"DateLastRefreshed"
|
"DateLastRefreshed",
|
||||||
|
"Name",
|
||||||
|
"Path",
|
||||||
|
"PremiereDate",
|
||||||
|
"Overview",
|
||||||
|
"ParentIndexNumber",
|
||||||
|
"ProductionYear",
|
||||||
|
"OfficialRating",
|
||||||
|
"OfficialRatingDescription",
|
||||||
|
"HomePageUrl",
|
||||||
|
"DisplayMediaType",
|
||||||
|
"ForcedSortName",
|
||||||
|
"RunTimeTicks",
|
||||||
|
"VoteCount",
|
||||||
|
"DateCreated",
|
||||||
|
"DateModified",
|
||||||
|
"guid",
|
||||||
|
"Genres",
|
||||||
|
"ParentId",
|
||||||
|
"Audio",
|
||||||
|
"ExternalServiceId"
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly string[] _mediaStreamSaveColumns =
|
private readonly string[] _mediaStreamSaveColumns =
|
||||||
|
@ -338,7 +385,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
"IsAnamorphic",
|
"IsAnamorphic",
|
||||||
"RefFrames",
|
"RefFrames",
|
||||||
"IsCabac",
|
"IsCabac",
|
||||||
"KeyFrames"
|
"CodecTag"
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -378,6 +425,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
"ParentId",
|
"ParentId",
|
||||||
"Genres",
|
"Genres",
|
||||||
"ParentalRatingValue",
|
"ParentalRatingValue",
|
||||||
|
"InheritedParentalRatingValue",
|
||||||
"SchemaVersion",
|
"SchemaVersion",
|
||||||
"SortName",
|
"SortName",
|
||||||
"RunTimeTicks",
|
"RunTimeTicks",
|
||||||
|
@ -394,7 +442,17 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
"PreferredMetadataCountryCode",
|
"PreferredMetadataCountryCode",
|
||||||
"IsHD",
|
"IsHD",
|
||||||
"ExternalEtag",
|
"ExternalEtag",
|
||||||
"DateLastRefreshed"
|
"DateLastRefreshed",
|
||||||
|
"DateLastSaved",
|
||||||
|
"IsInMixedFolder",
|
||||||
|
"LockedFields",
|
||||||
|
"Studios",
|
||||||
|
"Audio",
|
||||||
|
"ExternalServiceId",
|
||||||
|
"Tags",
|
||||||
|
"IsFolder",
|
||||||
|
"UnratedType",
|
||||||
|
"TopParentId"
|
||||||
};
|
};
|
||||||
_saveItemCommand = _connection.CreateCommand();
|
_saveItemCommand = _connection.CreateCommand();
|
||||||
_saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values (";
|
_saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values (";
|
||||||
|
@ -438,6 +496,17 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
_savePersonCommand.Parameters.Add(_savePersonCommand, "@SortOrder");
|
_savePersonCommand.Parameters.Add(_savePersonCommand, "@SortOrder");
|
||||||
_savePersonCommand.Parameters.Add(_savePersonCommand, "@ListOrder");
|
_savePersonCommand.Parameters.Add(_savePersonCommand, "@ListOrder");
|
||||||
|
|
||||||
|
// Ancestors
|
||||||
|
_deleteAncestorsCommand = _connection.CreateCommand();
|
||||||
|
_deleteAncestorsCommand.CommandText = "delete from AncestorIds where ItemId=@Id";
|
||||||
|
_deleteAncestorsCommand.Parameters.Add(_deleteAncestorsCommand, "@Id");
|
||||||
|
|
||||||
|
_saveAncestorCommand = _connection.CreateCommand();
|
||||||
|
_saveAncestorCommand.CommandText = "insert into AncestorIds (ItemId, AncestorId, AncestorIdText) values (@ItemId, @AncestorId, @AncestorIdText)";
|
||||||
|
_saveAncestorCommand.Parameters.Add(_saveAncestorCommand, "@ItemId");
|
||||||
|
_saveAncestorCommand.Parameters.Add(_saveAncestorCommand, "@AncestorId");
|
||||||
|
_saveAncestorCommand.Parameters.Add(_saveAncestorCommand, "@AncestorIdText");
|
||||||
|
|
||||||
// Chapters
|
// Chapters
|
||||||
_deleteChaptersCommand = _connection.CreateCommand();
|
_deleteChaptersCommand = _connection.CreateCommand();
|
||||||
_deleteChaptersCommand.CommandText = "delete from " + ChaptersTableName + " where ItemId=@ItemId";
|
_deleteChaptersCommand.CommandText = "delete from " + ChaptersTableName + " where ItemId=@ItemId";
|
||||||
|
@ -467,6 +536,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
{
|
{
|
||||||
_saveStreamCommand.Parameters.Add(_saveStreamCommand, "@" + col);
|
_saveStreamCommand.Parameters.Add(_saveStreamCommand, "@" + col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_updateInheritedRatingCommand = _connection.CreateCommand();
|
||||||
|
_updateInheritedRatingCommand.CommandText = "Update TypedBaseItems set InheritedParentalRatingValue=@InheritedParentalRatingValue where Guid=@Guid";
|
||||||
|
_updateInheritedRatingCommand.Parameters.Add(_updateInheritedRatingCommand, "@InheritedParentalRatingValue");
|
||||||
|
_updateInheritedRatingCommand.Parameters.Add(_updateInheritedRatingCommand, "@Guid");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -592,7 +666,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
}
|
}
|
||||||
|
|
||||||
_saveItemCommand.GetParameter(index++).Value = string.Join("|", item.Genres.ToArray());
|
_saveItemCommand.GetParameter(index++).Value = string.Join("|", item.Genres.ToArray());
|
||||||
_saveItemCommand.GetParameter(index++).Value = item.GetParentalRatingValue();
|
_saveItemCommand.GetParameter(index++).Value = item.GetParentalRatingValue() ?? 0;
|
||||||
|
_saveItemCommand.GetParameter(index++).Value = item.GetInheritedParentalRatingValue() ?? 0;
|
||||||
|
|
||||||
_saveItemCommand.GetParameter(index++).Value = LatestSchemaVersion;
|
_saveItemCommand.GetParameter(index++).Value = LatestSchemaVersion;
|
||||||
_saveItemCommand.GetParameter(index++).Value = item.SortName;
|
_saveItemCommand.GetParameter(index++).Value = item.SortName;
|
||||||
|
@ -623,9 +698,53 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
_saveItemCommand.GetParameter(index++).Value = item.DateLastRefreshed;
|
_saveItemCommand.GetParameter(index++).Value = item.DateLastRefreshed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_saveItemCommand.GetParameter(index++).Value = item.DateLastSaved;
|
||||||
|
_saveItemCommand.GetParameter(index++).Value = item.IsInMixedFolder;
|
||||||
|
_saveItemCommand.GetParameter(index++).Value = string.Join("|", item.LockedFields.Select(i => i.ToString()).ToArray());
|
||||||
|
_saveItemCommand.GetParameter(index++).Value = string.Join("|", item.Studios.ToArray());
|
||||||
|
|
||||||
|
if (item.Audio.HasValue)
|
||||||
|
{
|
||||||
|
_saveItemCommand.GetParameter(index++).Value = item.Audio.Value.ToString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_saveItemCommand.GetParameter(index++).Value = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var tvItem = item as ILiveTvItem;
|
||||||
|
if (tvItem != null)
|
||||||
|
{
|
||||||
|
_saveItemCommand.GetParameter(index++).Value = tvItem.ServiceName;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_saveItemCommand.GetParameter(index++).Value = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_saveItemCommand.GetParameter(index++).Value = string.Join("|", item.Tags.ToArray());
|
||||||
|
_saveItemCommand.GetParameter(index++).Value = item.IsFolder;
|
||||||
|
|
||||||
|
_saveItemCommand.GetParameter(index++).Value = item.GetBlockUnratedType().ToString();
|
||||||
|
|
||||||
|
var topParent = item.GetTopParent();
|
||||||
|
if (topParent != null)
|
||||||
|
{
|
||||||
|
_saveItemCommand.GetParameter(index++).Value = topParent.Id.ToString("N");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_saveItemCommand.GetParameter(index++).Value = null;
|
||||||
|
}
|
||||||
|
|
||||||
_saveItemCommand.Transaction = transaction;
|
_saveItemCommand.Transaction = transaction;
|
||||||
|
|
||||||
_saveItemCommand.ExecuteNonQuery();
|
_saveItemCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
|
if (item.SupportsAncestors)
|
||||||
|
{
|
||||||
|
UpdateAncestors(item.Id, item.GetAncestorIds().Distinct().ToList(), transaction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
|
@ -706,22 +825,32 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseItem item;
|
BaseItem item = null;
|
||||||
|
|
||||||
using (var stream = reader.GetMemoryStream(1))
|
using (var stream = reader.GetMemoryStream(1))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
item = _jsonSerializer.DeserializeFromStream(stream, type) as BaseItem;
|
item = _jsonSerializer.DeserializeFromStream(stream, type) as BaseItem;
|
||||||
|
|
||||||
if (item == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (SerializationException ex)
|
catch (SerializationException ex)
|
||||||
{
|
{
|
||||||
_logger.ErrorException("Error deserializing item", ex);
|
_logger.ErrorException("Error deserializing item", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item == null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
item = Activator.CreateInstance(type) as BaseItem;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -844,6 +973,107 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
item.DateLastRefreshed = reader.GetDateTime(23).ToUniversalTime();
|
item.DateLastRefreshed = reader.GetDateTime(23).ToUniversalTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(24))
|
||||||
|
{
|
||||||
|
item.Name = reader.GetString(24);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(25))
|
||||||
|
{
|
||||||
|
item.Path = reader.GetString(25);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(26))
|
||||||
|
{
|
||||||
|
item.PremiereDate = reader.GetDateTime(26).ToUniversalTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(27))
|
||||||
|
{
|
||||||
|
item.Overview = reader.GetString(27);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(28))
|
||||||
|
{
|
||||||
|
item.ParentIndexNumber = reader.GetInt32(28);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(29))
|
||||||
|
{
|
||||||
|
item.ProductionYear = reader.GetInt32(29);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(30))
|
||||||
|
{
|
||||||
|
item.OfficialRating = reader.GetString(30);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(31))
|
||||||
|
{
|
||||||
|
item.OfficialRating = reader.GetString(31);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(32))
|
||||||
|
{
|
||||||
|
item.HomePageUrl = reader.GetString(32);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(33))
|
||||||
|
{
|
||||||
|
item.DisplayMediaType = reader.GetString(33);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(34))
|
||||||
|
{
|
||||||
|
item.ForcedSortName = reader.GetString(34);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(35))
|
||||||
|
{
|
||||||
|
item.RunTimeTicks = reader.GetInt64(35);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(36))
|
||||||
|
{
|
||||||
|
item.VoteCount = reader.GetInt32(36);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(37))
|
||||||
|
{
|
||||||
|
item.DateCreated = reader.GetDateTime(37).ToUniversalTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(38))
|
||||||
|
{
|
||||||
|
item.DateModified = reader.GetDateTime(38).ToUniversalTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
item.Id = reader.GetGuid(39);
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(40))
|
||||||
|
{
|
||||||
|
item.Genres = reader.GetString(40).Split('|').Where(i => !string.IsNullOrWhiteSpace(i)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(41))
|
||||||
|
{
|
||||||
|
item.ParentId = reader.GetGuid(41);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(42))
|
||||||
|
{
|
||||||
|
item.Audio = (ProgramAudio)Enum.Parse(typeof(ProgramAudio), reader.GetString(42), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(43))
|
||||||
|
{
|
||||||
|
var tvItem = item as ILiveTvItem;
|
||||||
|
if (tvItem != null)
|
||||||
|
{
|
||||||
|
tvItem.ServiceName = reader.GetString(43);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1168,6 +1398,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
cmd.Parameters.Add(cmd, "@ParentId", DbType.Guid).Value = parentId;
|
cmd.Parameters.Add(cmd, "@ParentId", DbType.Guid).Value = parentId;
|
||||||
|
|
||||||
|
//_logger.Debug(cmd.CommandText);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
|
@ -1213,6 +1445,50 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<BaseItem> GetItemList(InternalItemsQuery query)
|
||||||
|
{
|
||||||
|
if (query == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("query");
|
||||||
|
}
|
||||||
|
|
||||||
|
CheckDisposed();
|
||||||
|
|
||||||
|
using (var cmd = _connection.CreateCommand())
|
||||||
|
{
|
||||||
|
cmd.CommandText = "select " + string.Join(",", _retriveItemColumns) + " from TypedBaseItems";
|
||||||
|
|
||||||
|
var whereClauses = GetWhereClauses(query, cmd, true);
|
||||||
|
|
||||||
|
var whereText = whereClauses.Count == 0 ?
|
||||||
|
string.Empty :
|
||||||
|
" where " + string.Join(" AND ", whereClauses.ToArray());
|
||||||
|
|
||||||
|
cmd.CommandText += whereText;
|
||||||
|
|
||||||
|
cmd.CommandText += GetOrderByText(query);
|
||||||
|
|
||||||
|
if (query.Limit.HasValue)
|
||||||
|
{
|
||||||
|
cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(CultureInfo.InvariantCulture);
|
||||||
|
}
|
||||||
|
|
||||||
|
//_logger.Debug(cmd.CommandText);
|
||||||
|
|
||||||
|
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
var item = GetItem(reader);
|
||||||
|
if (item != null)
|
||||||
|
{
|
||||||
|
yield return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public QueryResult<BaseItem> GetItems(InternalItemsQuery query)
|
public QueryResult<BaseItem> GetItems(InternalItemsQuery query)
|
||||||
{
|
{
|
||||||
if (query == null)
|
if (query == null)
|
||||||
|
@ -1293,6 +1569,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
private string MapOrderByField(string name)
|
private string MapOrderByField(string name)
|
||||||
{
|
{
|
||||||
|
if (string.Equals(name, "airtime", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return "SortName";
|
||||||
|
}
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1328,7 +1610,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
_logger.Debug(cmd.CommandText);
|
_logger.Debug(cmd.CommandText);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
|
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -1512,6 +1794,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
whereClauses.Add("IsSports=@IsSports");
|
whereClauses.Add("IsSports=@IsSports");
|
||||||
cmd.Parameters.Add(cmd, "@IsSports", DbType.Boolean).Value = query.IsSports;
|
cmd.Parameters.Add(cmd, "@IsSports", DbType.Boolean).Value = query.IsSports;
|
||||||
}
|
}
|
||||||
|
if (query.IsFolder.HasValue)
|
||||||
|
{
|
||||||
|
whereClauses.Add("IsFolder=@IsFolder");
|
||||||
|
cmd.Parameters.Add(cmd, "@IsFolder", DbType.Boolean).Value = query.IsFolder;
|
||||||
|
}
|
||||||
|
|
||||||
var includeTypes = query.IncludeItemTypes.SelectMany(MapIncludeItemTypes).ToArray();
|
var includeTypes = query.IncludeItemTypes.SelectMany(MapIncludeItemTypes).ToArray();
|
||||||
if (includeTypes.Length == 1)
|
if (includeTypes.Length == 1)
|
||||||
|
@ -1572,6 +1859,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
cmd.Parameters.Add(cmd, "@MinStartDate", DbType.Date).Value = query.MinStartDate.Value;
|
cmd.Parameters.Add(cmd, "@MinStartDate", DbType.Date).Value = query.MinStartDate.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (query.MinPremiereDate.HasValue)
|
||||||
|
{
|
||||||
|
whereClauses.Add("PremiereDate>=@MinPremiereDate");
|
||||||
|
cmd.Parameters.Add(cmd, "@MinPremiereDate", DbType.Date).Value = query.MinPremiereDate.Value;
|
||||||
|
}
|
||||||
|
|
||||||
if (query.MaxStartDate.HasValue)
|
if (query.MaxStartDate.HasValue)
|
||||||
{
|
{
|
||||||
whereClauses.Add("StartDate<=@MaxStartDate");
|
whereClauses.Add("StartDate<=@MaxStartDate");
|
||||||
|
@ -1623,7 +1916,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
if (query.MaxParentalRating.HasValue)
|
if (query.MaxParentalRating.HasValue)
|
||||||
{
|
{
|
||||||
whereClauses.Add("(ParentalRatingValue is NULL OR ParentalRatingValue<=@MaxParentalRating)");
|
whereClauses.Add("InheritedParentalRatingValue<=@MaxParentalRating");
|
||||||
cmd.Parameters.Add(cmd, "@MaxParentalRating", DbType.Int32).Value = query.MaxParentalRating.Value;
|
cmd.Parameters.Add(cmd, "@MaxParentalRating", DbType.Int32).Value = query.MaxParentalRating.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1631,11 +1924,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
{
|
{
|
||||||
if (query.HasParentalRating.Value)
|
if (query.HasParentalRating.Value)
|
||||||
{
|
{
|
||||||
whereClauses.Add("ParentalRatingValue NOT NULL");
|
whereClauses.Add("InheritedParentalRatingValue > 0");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
whereClauses.Add("ParentalRatingValue IS NULL");
|
whereClauses.Add("InheritedParentalRatingValue = 0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1646,7 +1939,60 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
whereClauses.Add("ParentId NOT NULL AND ParentId NOT IN (select guid from TypedBaseItems)");
|
whereClauses.Add("ParentId NOT NULL AND ParentId NOT IN (select guid from TypedBaseItems)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (query.ExcludeLocationTypes.Length == 1)
|
||||||
|
{
|
||||||
|
whereClauses.Add("LocationType<>@LocationType");
|
||||||
|
cmd.Parameters.Add(cmd, "@LocationType", DbType.String).Value = query.ExcludeLocationTypes[0].ToString();
|
||||||
|
}
|
||||||
|
if (query.ExcludeLocationTypes.Length > 1)
|
||||||
|
{
|
||||||
|
var val = string.Join(",", query.ExcludeLocationTypes.Select(i => "'" + i + "'").ToArray());
|
||||||
|
|
||||||
|
whereClauses.Add("LocationType not in (" + val + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query.TopParentIds.Length == 1)
|
||||||
|
{
|
||||||
|
whereClauses.Add("(TopParentId=@TopParentId)");
|
||||||
|
cmd.Parameters.Add(cmd, "@TopParentId", DbType.String).Value = query.TopParentIds[0];
|
||||||
|
}
|
||||||
|
if (query.TopParentIds.Length > 1)
|
||||||
|
{
|
||||||
|
var val = string.Join(",", query.TopParentIds.Select(i => "'" + i + "'").ToArray());
|
||||||
|
|
||||||
|
whereClauses.Add("(TopParentId in (" + val + "))");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query.AncestorIds.Length == 1)
|
||||||
|
{
|
||||||
|
whereClauses.Add("Guid in (select itemId from AncestorIds where AncestorId=@AncestorId)");
|
||||||
|
cmd.Parameters.Add(cmd, "@AncestorId", DbType.Guid).Value = new Guid(query.AncestorIds[0]);
|
||||||
|
}
|
||||||
|
if (query.AncestorIds.Length > 1)
|
||||||
|
{
|
||||||
|
var inClause = string.Join(",", query.AncestorIds.Select(i => "'" + new Guid(i).ToString("N") + "'").ToArray());
|
||||||
|
whereClauses.Add(string.Format("Guid in (select itemId from AncestorIds where AncestorIdText in ({0}))", inClause));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query.BlockUnratedItems.Length == 1)
|
||||||
|
{
|
||||||
|
whereClauses.Add("(InheritedParentalRatingValue > 0 or UnratedType <> @UnratedType)");
|
||||||
|
cmd.Parameters.Add(cmd, "@UnratedType", DbType.String).Value = query.BlockUnratedItems[0].ToString();
|
||||||
|
}
|
||||||
|
if (query.BlockUnratedItems.Length > 1)
|
||||||
|
{
|
||||||
|
var inClause = string.Join(",", query.BlockUnratedItems.Select(i => "'" + i.ToString() + "'").ToArray());
|
||||||
|
whereClauses.Add(string.Format("(InheritedParentalRatingValue > 0 or UnratedType not in ({0}))", inClause));
|
||||||
|
}
|
||||||
|
|
||||||
|
//var excludeTagIndex = 0;
|
||||||
|
//foreach (var excludeTag in query.ExcludeTags)
|
||||||
|
//{
|
||||||
|
// whereClauses.Add("Tags not like @excludeTag" + excludeTagIndex);
|
||||||
|
// cmd.Parameters.Add(cmd, "@excludeTag" + excludeTagIndex, DbType.String).Value = "%" + excludeTag + "%";
|
||||||
|
// excludeTagIndex++;
|
||||||
|
//}
|
||||||
|
|
||||||
if (addPaging)
|
if (addPaging)
|
||||||
{
|
{
|
||||||
if (query.StartIndex.HasValue && query.StartIndex.Value > 0)
|
if (query.StartIndex.HasValue && query.StartIndex.Value > 0)
|
||||||
|
@ -1703,6 +2049,83 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
typeof(AggregateFolder)
|
typeof(AggregateFolder)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public async Task UpdateInheritedValues(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var newValues = new List<Tuple<Guid, int>>();
|
||||||
|
|
||||||
|
using (var cmd = _connection.CreateCommand())
|
||||||
|
{
|
||||||
|
cmd.CommandText = "select Guid,InheritedParentalRatingValue,(select Max(ParentalRatingValue, (select COALESCE(MAX(ParentalRatingValue),0) from TypedBaseItems where guid in (Select AncestorId from AncestorIds where ItemId=Outer.guid)))) as NewInheritedParentalRatingValue from typedbaseitems as Outer where InheritedParentalRatingValue <> NewInheritedParentalRatingValue";
|
||||||
|
|
||||||
|
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
var id = reader.GetGuid(0);
|
||||||
|
var newValue = reader.GetInt32(2);
|
||||||
|
|
||||||
|
newValues.Add(new Tuple<Guid, int>(id, newValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newValues.Count == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
IDbTransaction transaction = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
transaction = _connection.BeginTransaction();
|
||||||
|
|
||||||
|
foreach (var item in newValues)
|
||||||
|
{
|
||||||
|
_updateInheritedRatingCommand.GetParameter(0).Value = item.Item1;
|
||||||
|
_updateInheritedRatingCommand.GetParameter(1).Value = item.Item2;
|
||||||
|
|
||||||
|
_updateInheritedRatingCommand.Transaction = transaction;
|
||||||
|
_updateInheritedRatingCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
|
_updateInheritedRatingCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
if (transaction != null)
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.ErrorException("Error running query:", e);
|
||||||
|
|
||||||
|
if (transaction != null)
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (transaction != null)
|
||||||
|
{
|
||||||
|
transaction.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
_writeLock.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static Dictionary<string, string[]> GetTypeMapDictionary()
|
private static Dictionary<string, string[]> GetTypeMapDictionary()
|
||||||
{
|
{
|
||||||
var dict = new Dictionary<string, string[]>();
|
var dict = new Dictionary<string, string[]>();
|
||||||
|
@ -1712,6 +2135,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
dict[t.Name] = new[] { t.FullName };
|
dict[t.Name] = new[] { t.FullName };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dict["ChannelItem"] = new[] { typeof(ChannelVideoItem).FullName, typeof(ChannelAudioItem).FullName, typeof(ChannelFolderItem).FullName };
|
||||||
|
dict["LiveTvItem"] = new[] { typeof(LiveTvAudioRecording).FullName, typeof(LiveTvVideoRecording).FullName, typeof(LiveTvChannel).FullName, typeof(LiveTvProgram).FullName };
|
||||||
dict["Recording"] = new[] { typeof(LiveTvAudioRecording).FullName, typeof(LiveTvVideoRecording).FullName };
|
dict["Recording"] = new[] { typeof(LiveTvAudioRecording).FullName, typeof(LiveTvVideoRecording).FullName };
|
||||||
dict["Program"] = new[] { typeof(LiveTvProgram).FullName };
|
dict["Program"] = new[] { typeof(LiveTvProgram).FullName };
|
||||||
dict["TvChannel"] = new[] { typeof(LiveTvChannel).FullName };
|
dict["TvChannel"] = new[] { typeof(LiveTvChannel).FullName };
|
||||||
|
@ -1770,11 +2195,16 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
_deleteStreamsCommand.Transaction = transaction;
|
_deleteStreamsCommand.Transaction = transaction;
|
||||||
_deleteStreamsCommand.ExecuteNonQuery();
|
_deleteStreamsCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
|
// Delete ancestors
|
||||||
|
_deleteAncestorsCommand.GetParameter(0).Value = id;
|
||||||
|
_deleteAncestorsCommand.Transaction = transaction;
|
||||||
|
_deleteAncestorsCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
// Delete the item
|
// Delete the item
|
||||||
_deleteItemCommand.GetParameter(0).Value = id;
|
_deleteItemCommand.GetParameter(0).Value = id;
|
||||||
_deleteItemCommand.Transaction = transaction;
|
_deleteItemCommand.Transaction = transaction;
|
||||||
_deleteItemCommand.ExecuteNonQuery();
|
_deleteItemCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
|
@ -2003,6 +2433,38 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
return whereClauses;
|
return whereClauses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateAncestors(Guid itemId, List<Guid> ancestorIds, IDbTransaction transaction)
|
||||||
|
{
|
||||||
|
if (itemId == Guid.Empty)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("itemId");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ancestorIds == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("ancestorIds");
|
||||||
|
}
|
||||||
|
|
||||||
|
CheckDisposed();
|
||||||
|
|
||||||
|
// First delete
|
||||||
|
_deleteAncestorsCommand.GetParameter(0).Value = itemId;
|
||||||
|
_deleteAncestorsCommand.Transaction = transaction;
|
||||||
|
|
||||||
|
_deleteAncestorsCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
|
foreach (var ancestorId in ancestorIds)
|
||||||
|
{
|
||||||
|
_saveAncestorCommand.GetParameter(0).Value = itemId;
|
||||||
|
_saveAncestorCommand.GetParameter(1).Value = ancestorId;
|
||||||
|
_saveAncestorCommand.GetParameter(2).Value = ancestorId.ToString("N");
|
||||||
|
|
||||||
|
_saveAncestorCommand.Transaction = transaction;
|
||||||
|
|
||||||
|
_saveAncestorCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task UpdatePeople(Guid itemId, List<PersonInfo> people)
|
public async Task UpdatePeople(Guid itemId, List<PersonInfo> people)
|
||||||
{
|
{
|
||||||
if (itemId == Guid.Empty)
|
if (itemId == Guid.Empty)
|
||||||
|
@ -2220,7 +2682,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
_saveStreamCommand.GetParameter(index++).Value = stream.RefFrames;
|
_saveStreamCommand.GetParameter(index++).Value = stream.RefFrames;
|
||||||
_saveStreamCommand.GetParameter(index++).Value = stream.IsCabac;
|
_saveStreamCommand.GetParameter(index++).Value = stream.IsCabac;
|
||||||
|
|
||||||
_saveStreamCommand.GetParameter(index++).Value = null;
|
_saveStreamCommand.GetParameter(index++).Value = stream.CodecTag;
|
||||||
|
|
||||||
_saveStreamCommand.Transaction = transaction;
|
_saveStreamCommand.Transaction = transaction;
|
||||||
_saveStreamCommand.ExecuteNonQuery();
|
_saveStreamCommand.ExecuteNonQuery();
|
||||||
|
@ -2376,10 +2838,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
if (!reader.IsDBNull(26))
|
if (!reader.IsDBNull(26))
|
||||||
{
|
{
|
||||||
var frames = reader.GetString(26);
|
item.CodecTag = reader.GetString(26);
|
||||||
if (!string.IsNullOrWhiteSpace(frames))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user