Skip to content

Commit

Permalink
remove a double lookup, on v8.4+ umbraco installs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Jump committed Dec 19, 2019
1 parent 951606f commit 40010d9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
20 changes: 16 additions & 4 deletions uSync8.ContentEdition/Serializers/ContentSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Xml.Linq;

using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
Expand All @@ -23,6 +24,8 @@ public class ContentSerializer : ContentSerializerBase<IContent>, ISyncSerialize
protected readonly IContentService contentService;
protected readonly IFileService fileService;

private bool performDoubleLookup;

public ContentSerializer(
IEntityService entityService,
ILocalizationService localizationService,
Expand All @@ -34,6 +37,8 @@ public ContentSerializer(
{
this.contentService = contentService;
this.fileService = fileService;

performDoubleLookup = UmbracoVersion.LocalVersion.Major != 8 || UmbracoVersion.LocalVersion.Minor < 4;
}

#region Serialization
Expand Down Expand Up @@ -293,10 +298,17 @@ protected override IContent FindItem(int id)

protected override IContent FindItem(Guid key)
{
// TODO: Umbraco 8 bug, the key isn sometimes an old version
var entity = entityService.Get(key);
if (entity != null)
return contentService.GetById(entity.Id);
if (performDoubleLookup)
{
// fixed v8.4+ by https://github.com/umbraco/Umbraco-CMS/issues/2997
var entity = entityService.Get(key);
if (entity != null)
return contentService.GetById(entity.Id);
}
else
{
return contentService.GetById(key);
}

return null;
}
Expand Down
2 changes: 2 additions & 0 deletions uSync8.ContentEdition/Serializers/ContentSerializerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ protected virtual XElement SerializeInfo(TObject item)
info.Add(new XElement("ContentType", item.ContentType.Alias));
info.Add(new XElement("CreateDate", item.CreateDate));

info.Add(new XElement("Version", item.VersionId));

var title = new XElement("NodeName", new XAttribute("Default", item.Name));
foreach (var culture in item.AvailableCultures)
{
Expand Down
21 changes: 17 additions & 4 deletions uSync8.ContentEdition/Serializers/MediaSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Newtonsoft.Json;

using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
Expand All @@ -28,6 +29,9 @@ public class MediaSerializer : ContentSerializerBase<IMedia>, ISyncSerializer<IM
{
private readonly IMediaService mediaService;

private bool performDoubleLookup;


public MediaSerializer(
IEntityService entityService,
ILocalizationService localizationService,
Expand All @@ -47,6 +51,8 @@ public MediaSerializer(
"umbracoWidth", "umbracoHeight", "umbracoBytes", "umbracoExtension"
};

performDoubleLookup = UmbracoVersion.LocalVersion.Major != 8 || UmbracoVersion.LocalVersion.Minor < 4;

}

protected override SyncAttempt<IMedia> DeserializeCore(XElement node)
Expand Down Expand Up @@ -174,10 +180,17 @@ protected override IMedia FindItem(int id)

protected override IMedia FindItem(Guid key)
{
// TODO: Umbraco 8 bug, find by key sometimes returns an old version
var entity = entityService.Get(key);
if (entity != null)
return mediaService.GetById(entity.Id);
if (performDoubleLookup)
{
// fixed v8.4+ by https://github.com/umbraco/Umbraco-CMS/issues/2997
var entity = entityService.Get(key);
if (entity != null)
return mediaService.GetById(entity.Id);
}
else
{
return mediaService.GetById(key);
}

return null;
}
Expand Down

0 comments on commit 40010d9

Please sign in to comment.