Merge pull request #2103 from MediaBrowser/dev

fix sync container statuses
This commit is contained in:
Luke 2016-08-26 13:26:41 -04:00 committed by GitHub
commit 07bdea0322
7 changed files with 113 additions and 120 deletions

View File

@ -304,7 +304,7 @@ namespace MediaBrowser.Api
item.EndDate = request.EndDate.HasValue ? NormalizeDateTime(request.EndDate.Value) : (DateTime?)null; item.EndDate = request.EndDate.HasValue ? NormalizeDateTime(request.EndDate.Value) : (DateTime?)null;
item.PremiereDate = request.PremiereDate.HasValue ? NormalizeDateTime(request.PremiereDate.Value) : (DateTime?)null; item.PremiereDate = request.PremiereDate.HasValue ? NormalizeDateTime(request.PremiereDate.Value) : (DateTime?)null;
item.ProductionYear = request.ProductionYear; item.ProductionYear = request.ProductionYear;
item.OfficialRating = request.OfficialRating; item.OfficialRating = string.IsNullOrWhiteSpace(request.OfficialRating) ? null : request.OfficialRating;
item.CustomRating = request.CustomRating; item.CustomRating = request.CustomRating;
SetProductionLocations(item, request); SetProductionLocations(item, request);

View File

@ -781,6 +781,9 @@ namespace MediaBrowser.Controller.Entities
[IgnoreDataMember] [IgnoreDataMember]
public string OfficialRating { get; set; } public string OfficialRating { get; set; }
[IgnoreDataMember]
public int InheritedParentalRatingValue { get; set; }
/// <summary> /// <summary>
/// Gets or sets the critic rating. /// Gets or sets the critic rating.
/// </summary> /// </summary>

View File

@ -59,5 +59,8 @@ namespace MediaBrowser.Controller.Entities
string GetPresentationUniqueKey(); string GetPresentationUniqueKey();
string CreatePresentationUniqueKey(); string CreatePresentationUniqueKey();
bool StopRefreshIfLocalMetadataFound { get; } bool StopRefreshIfLocalMetadataFound { get; }
int? GetInheritedParentalRatingValue();
int InheritedParentalRatingValue { get; set; }
} }
} }

View File

@ -294,6 +294,13 @@ namespace MediaBrowser.Providers.Manager
updateType |= ItemUpdateType.MetadataImport; updateType |= ItemUpdateType.MetadataImport;
} }
var inheritedParentalRatingValue = item.GetInheritedParentalRatingValue() ?? 0;
if (inheritedParentalRatingValue != item.InheritedParentalRatingValue)
{
item.InheritedParentalRatingValue = inheritedParentalRatingValue;
updateType |= ItemUpdateType.MetadataImport;
}
return updateType; return updateType;
} }

View File

@ -92,7 +92,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
private IDbCommand _deleteImagesCommand; private IDbCommand _deleteImagesCommand;
private IDbCommand _saveImagesCommand; private IDbCommand _saveImagesCommand;
private IDbCommand _updateInheritedRatingCommand;
private IDbCommand _updateInheritedTagsCommand; private IDbCommand _updateInheritedTagsCommand;
public const int LatestSchemaVersion = 109; public const int LatestSchemaVersion = 109;
@ -412,7 +411,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
"SeasonId", "SeasonId",
"SeriesId", "SeriesId",
"SeriesSortName", "SeriesSortName",
"PresentationUniqueKey" "PresentationUniqueKey",
"InheritedParentalRatingValue"
}; };
private readonly string[] _mediaStreamSaveColumns = private readonly string[] _mediaStreamSaveColumns =
@ -611,11 +611,6 @@ 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, "@Guid");
_updateInheritedRatingCommand.Parameters.Add(_updateInheritedRatingCommand, "@InheritedParentalRatingValue");
_updateInheritedTagsCommand = _connection.CreateCommand(); _updateInheritedTagsCommand = _connection.CreateCommand();
_updateInheritedTagsCommand.CommandText = "Update TypedBaseItems set InheritedTags=@InheritedTags where Guid=@Guid"; _updateInheritedTagsCommand.CommandText = "Update TypedBaseItems set InheritedTags=@InheritedTags where Guid=@Guid";
_updateInheritedTagsCommand.Parameters.Add(_updateInheritedTagsCommand, "@Guid"); _updateInheritedTagsCommand.Parameters.Add(_updateInheritedTagsCommand, "@Guid");
@ -1458,6 +1453,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
} }
index++; index++;
if (!reader.IsDBNull(index))
{
item.InheritedParentalRatingValue = reader.GetInt32(index);
}
index++;
return item; return item;
} }
@ -3402,7 +3403,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
public async Task UpdateInheritedValues(CancellationToken cancellationToken) public async Task UpdateInheritedValues(CancellationToken cancellationToken)
{ {
await UpdateInheritedParentalRating(cancellationToken).ConfigureAwait(false);
await UpdateInheritedTags(cancellationToken).ConfigureAwait(false); await UpdateInheritedTags(cancellationToken).ConfigureAwait(false);
} }
@ -3482,82 +3482,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
} }
} }
private async Task UpdateInheritedParentalRating(CancellationToken cancellationToken)
{
var newValues = new List<Tuple<Guid, int>>();
using (var cmd = _connection.CreateCommand())
{
cmd.CommandText = "select Guid,InheritedParentalRatingValue,(select Max(InheritedParentalRatingValue, (select COALESCE(MAX(InheritedParentalRatingValue),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));
}
}
}
Logger.Debug("UpdateInheritedParentalRatings - {0} rows", newValues.Count);
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();
}
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[]>(StringComparer.OrdinalIgnoreCase); var dict = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);

View File

@ -47,15 +47,18 @@ namespace MediaBrowser.Server.Implementations.Sync
string[] queries = { string[] queries = {
"create table if not exists SyncJobs (Id GUID PRIMARY KEY, TargetId TEXT NOT NULL, Name TEXT NOT NULL, Profile TEXT, Quality TEXT, Bitrate INT, Status TEXT NOT NULL, Progress FLOAT, UserId TEXT NOT NULL, ItemIds TEXT NOT NULL, Category TEXT, ParentId TEXT, UnwatchedOnly BIT, ItemLimit INT, SyncNewContent BIT, DateCreated DateTime, DateLastModified DateTime, ItemCount int)", "create table if not exists SyncJobs (Id GUID PRIMARY KEY, TargetId TEXT NOT NULL, Name TEXT NOT NULL, Profile TEXT, Quality TEXT, Bitrate INT, Status TEXT NOT NULL, Progress FLOAT, UserId TEXT NOT NULL, ItemIds TEXT NOT NULL, Category TEXT, ParentId TEXT, UnwatchedOnly BIT, ItemLimit INT, SyncNewContent BIT, DateCreated DateTime, DateLastModified DateTime, ItemCount int)",
"create index if not exists idx_SyncJobs on SyncJobs(Id)",
"create index if not exists idx_SyncJobs1 on SyncJobs(TargetId)",
"create table if not exists SyncJobItems (Id GUID PRIMARY KEY, ItemId TEXT, ItemName TEXT, MediaSourceId TEXT, JobId TEXT, TemporaryPath TEXT, OutputPath TEXT, Status TEXT, TargetId TEXT, DateCreated DateTime, Progress FLOAT, AdditionalFiles TEXT, MediaSource TEXT, IsMarkedForRemoval BIT, JobItemIndex INT, ItemDateModifiedTicks BIGINT)", "create table if not exists SyncJobItems (Id GUID PRIMARY KEY, ItemId TEXT, ItemName TEXT, MediaSourceId TEXT, JobId TEXT, TemporaryPath TEXT, OutputPath TEXT, Status TEXT, TargetId TEXT, DateCreated DateTime, Progress FLOAT, AdditionalFiles TEXT, MediaSource TEXT, IsMarkedForRemoval BIT, JobItemIndex INT, ItemDateModifiedTicks BIGINT)",
"create index if not exists idx_SyncJobItems1 on SyncJobItems(Id)",
"drop index if exists idx_SyncJobItems2", "drop index if exists idx_SyncJobItems2",
"drop index if exists idx_SyncJobItems3", "drop index if exists idx_SyncJobItems3",
"drop index if exists idx_SyncJobs1",
"drop index if exists idx_SyncJobs",
"drop index if exists idx_SyncJobItems1",
"create index if not exists idx_SyncJobItems4 on SyncJobItems(TargetId,ItemId,Status,Progress,DateCreated)", "create index if not exists idx_SyncJobItems4 on SyncJobItems(TargetId,ItemId,Status,Progress,DateCreated)",
"create index if not exists idx_SyncJobItems5 on SyncJobItems(TargetId,Status,ItemId,Progress)",
"create index if not exists idx_SyncJobs2 on SyncJobs(TargetId,Status,ItemIds,Progress)",
"pragma shrink_memory" "pragma shrink_memory"
}; };
@ -641,37 +644,24 @@ namespace MediaBrowser.Server.Implementations.Sync
cmd.CommandText += " where " + string.Join(" AND ", whereClauses.ToArray()); cmd.CommandText += " where " + string.Join(" AND ", whereClauses.ToArray());
} }
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult)) cmd.CommandText += ";" + cmd.CommandText
.Replace("select ItemId,Status,Progress from SyncJobItems", "select ItemIds,Status,Progress from SyncJobs")
.Replace("'Synced'", "'Completed','CompletedWithError'");
Logger.Debug(cmd.CommandText);
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
{ {
while (reader.Read()) while (reader.Read())
{ {
var itemId = reader.GetString(0); AddStatusResult(reader, result, false);
}
if (!reader.IsDBNull(1)) if (reader.NextResult())
{
while (reader.Read())
{ {
var status = (SyncJobItemStatus)Enum.Parse(typeof(SyncJobItemStatus), reader.GetString(1), true); AddStatusResult(reader, result, true);
if (status == SyncJobItemStatus.Synced)
{
result[itemId] = new SyncedItemProgress
{
Status = SyncJobItemStatus.Synced
};
}
else
{
SyncedItemProgress currentStatus;
double progress = reader.IsDBNull(2) ? 0.0 : reader.GetDouble(2);
if (!result.TryGetValue(itemId, out currentStatus) || (currentStatus.Status != SyncJobItemStatus.Synced && progress >= currentStatus.Progress))
{
result[itemId] = new SyncedItemProgress
{
Status = status,
Progress = progress
};
}
}
} }
} }
} }
@ -681,6 +671,70 @@ namespace MediaBrowser.Server.Implementations.Sync
return result; return result;
} }
private void AddStatusResult(IDataReader reader, Dictionary<string, SyncedItemProgress> result, bool multipleIds)
{
if (reader.IsDBNull(0))
{
return;
}
var itemIds = new List<string>();
var ids = reader.GetString(0);
if (multipleIds)
{
itemIds = ids.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
}
else
{
itemIds.Add(ids);
}
if (!reader.IsDBNull(1))
{
SyncJobItemStatus status;
var statusString = reader.GetString(1);
if (string.Equals(statusString, "Completed", StringComparison.OrdinalIgnoreCase) ||
string.Equals(statusString, "CompletedWithError", StringComparison.OrdinalIgnoreCase))
{
status = SyncJobItemStatus.Synced;
}
else
{
status = (SyncJobItemStatus)Enum.Parse(typeof(SyncJobItemStatus), statusString, true);
}
if (status == SyncJobItemStatus.Synced)
{
foreach (var itemId in itemIds)
{
result[itemId] = new SyncedItemProgress
{
Status = SyncJobItemStatus.Synced
};
}
}
else
{
double progress = reader.IsDBNull(2) ? 0.0 : reader.GetDouble(2);
foreach (var itemId in itemIds)
{
SyncedItemProgress currentStatus;
if (!result.TryGetValue(itemId, out currentStatus) || (currentStatus.Status != SyncJobItemStatus.Synced && progress >= currentStatus.Progress))
{
result[itemId] = new SyncedItemProgress
{
Status = status,
Progress = progress
};
}
}
}
}
}
public QueryResult<SyncJobItem> GetJobItems(SyncJobItemQuery query) public QueryResult<SyncJobItem> GetJobItems(SyncJobItemQuery query)
{ {
return GetJobItemReader(query, BaseJobItemSelectText, GetJobItem); return GetJobItemReader(query, BaseJobItemSelectText, GetJobItem);

View File

@ -62,11 +62,12 @@ namespace MediaBrowser.Server.Startup.Common.Migrations
var newUpdateLevel = updateLevel; var newUpdateLevel = updateLevel;
if (releases.Count >= 2) // If the current version is later than current stable, set the update level to beta
if (releases.Count >= 1)
{ {
var beta = releases[1]; var release = releases[0];
Version version; Version version;
if (Version.TryParse(beta.tag_name, out version)) if (Version.TryParse(release.tag_name, out version))
{ {
if (currentVersion >= version) if (currentVersion >= version)
{ {
@ -75,11 +76,12 @@ namespace MediaBrowser.Server.Startup.Common.Migrations
} }
} }
if (releases.Count >= 3) // If the current version is later than current beta, set the update level to dev
if (releases.Count >= 2)
{ {
var dev = releases[2]; var release = releases[1];
Version version; Version version;
if (Version.TryParse(dev.tag_name, out version)) if (Version.TryParse(release.tag_name, out version))
{ {
if (currentVersion >= version) if (currentVersion >= version)
{ {