Refactor content culture & variations

This commit is contained in:
Stephan
2018-04-28 21:57:07 +02:00
parent 6959e595f5
commit 7dd1efb29f
17 changed files with 156 additions and 99 deletions

View File

@@ -18,7 +18,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
for (var i = 0; i < pcount; i++)
{
var languageId = PrimitiveSerializer.String.ReadFrom(stream);
var cultureVariation = new CultureVariation { Name = ReadStringObject(stream) };
var cultureVariation = new CultureVariation { Name = ReadStringObject(stream), Date = ReadDateTime(stream) };
dict[languageId] = cultureVariation;
}
return dict;
@@ -40,6 +40,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
PrimitiveSerializer.String.WriteTo(culture, stream); // should never be null
WriteObject(variation.Name, stream); // write an object in case it's null (though... should not happen)
PrimitiveSerializer.DateTime.WriteTo(variation.Date, stream);
}
}
}

View File

@@ -6,20 +6,18 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
// represents everything that is specific to edited or published version
internal class ContentData
{
public string Name { get; set; }
public int VersionId { get; set; }
public DateTime VersionDate { get; set; }
public int WriterId { get; set; }
public int TemplateId { get; set; }
public bool Published { get; set; }
public IDictionary<string, PropertyData[]> Properties { get; set; }
/// <summary>
/// The collection of language Id to name for the content item
/// </summary>
public IReadOnlyDictionary<string, CultureVariation> CultureInfos { get; set; }
public string Name { get; set; }
public int VersionId { get; set; }
//TODO: This will not make a lot of sense since we'll have dates for each variant publishing, need to wait on Stephane
public DateTime VersionDate { get; set; }
public int WriterId { get; set; }
public int TemplateId { get; set; }
public IDictionary<string, PropertyData[]> Properties { get; set; }
}
}

View File

@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System;
using Newtonsoft.Json;
namespace Umbraco.Web.PublishedCache.NuCache.DataSource
{
@@ -10,6 +11,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
[JsonProperty("name")]
public string Name { get; set; }
//TODO: We may want some date stamps here
[JsonProperty("date")]
public DateTime Date { get; set; }
}
}

View File

@@ -2,8 +2,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Collections;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web.PublishedCache.NuCache.DataSource;
@@ -19,6 +21,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
private readonly bool _isPreviewing;
private readonly bool _isMember;
private readonly PublishedContent _content;
private readonly ContentVariation _variations;
private readonly object _locko = new object();
@@ -68,6 +71,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
_isPreviewing = content.IsPreviewing;
_isMember = content.ContentType.ItemType == PublishedItemType.Member;
_publishedSnapshotAccessor = publishedSnapshotAccessor;
_variations = propertyType.Variations;
}
// clone for previewing as draft a published content that is published and has no draft
@@ -82,6 +86,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
_isPreviewing = true;
_isMember = origin._isMember;
_publishedSnapshotAccessor = origin._publishedSnapshotAccessor;
_variations = origin._variations;
}
public override bool HasValue(string culture = ".", string segment = ".") => _sourceValue != null
@@ -185,9 +190,10 @@ namespace Umbraco.Web.PublishedCache.NuCache
if (culture != "." && segment != ".") return;
// use context values
// fixme CultureSegment?
var publishedVariationContext = _content.VariationContextAccessor?.Context;
if (culture == ".") culture = publishedVariationContext?.Culture;
if (segment == ".") segment = publishedVariationContext?.Segment;
if (culture == ".") culture = _variations.Has(ContentVariation.CultureNeutral) ? publishedVariationContext?.Culture : null;
if (segment == ".") segment = _variations.Has(ContentVariation.CultureNeutral) ? publishedVariationContext?.Segment : null;
}
public override object GetValue(string culture = ".", string segment = ".")

View File

@@ -19,7 +19,6 @@ namespace Umbraco.Web.PublishedCache.NuCache
internal readonly ContentData _contentData; // internal for ContentNode cloning
private readonly string _urlSegment;
private IReadOnlyDictionary<string, PublishedCultureName> _cultureNames;
#region Constructors
@@ -265,7 +264,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
if (_cultureInfos != null) return _cultureInfos;
return _cultureInfos = _contentData.CultureInfos // fixme can it be null?
.ToDictionary(x => x.Key, x => new PublishedCultureInfos(x.Key, x.Value.Name, false, DateTime.MinValue)); // fixme values!
.ToDictionary(x => x.Key, x => new PublishedCultureInfos(x.Key, x.Value.Name, false, x.Value.Date)); // fixme values!
}
}

View File

@@ -722,7 +722,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
Notify<IContentType>(_contentStore, payloads, RefreshContentTypesLocked);
Notify<IMediaType>(_mediaStore, payloads, RefreshMediaTypesLocked);
((PublishedSnapshot)CurrentPublishedSnapshot).Resync();
((PublishedSnapshot)CurrentPublishedSnapshot)?.Resync(); // fixme all
}
private void Notify<T>(ContentStore store, ContentTypeCacheRefresher.JsonPayload[] payloads, Action<IEnumerable<int>, IEnumerable<int>, IEnumerable<int>, IEnumerable<int>> action)
@@ -799,7 +799,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
}
((PublishedSnapshot)CurrentPublishedSnapshot).Resync();
((PublishedSnapshot)CurrentPublishedSnapshot)?.Resync(); // fixme elsewhere!
}
public override void Notify(DomainCacheRefresher.JsonPayload[] payloads)
@@ -900,8 +900,9 @@ namespace Umbraco.Web.PublishedCache.NuCache
// contentStore is wlocked (so readable, only no new views)
// and it can be wlocked by 1 thread only at a time
if (!(_serviceContext.ContentService is ContentService))
throw new Exception("oops");
// fixme wtf?
//if (!(_serviceContext.ContentService is ContentService))
// throw new Exception("oops");
var refreshedIdsA = refreshedIds.ToArray();
@@ -1219,7 +1220,6 @@ namespace Umbraco.Web.PublishedCache.NuCache
var cultureData = new Dictionary<string, CultureVariation>();
// fixme refactor!!!
var names = content is IContent document
? (published
? document.PublishNames
@@ -1228,7 +1228,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
foreach (var (culture, name) in names)
{
cultureData[culture] = new CultureVariation { Name = name };
cultureData[culture] = new CultureVariation { Name = name, Date = content.GetCultureDate(culture) };
}
//the dictionary that will be serialized