Adds migration for binary column on cmsContentNu

This commit is contained in:
Shannon
2020-07-03 15:41:25 +10:00
parent de67bdc2a2
commit 39625d94dd
9 changed files with 66 additions and 14 deletions

View File

@@ -27,6 +27,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
public int EditWriterId { get; set; }
public int EditTemplateId { get; set; }
public string EditData { get; set; }
public byte[] EditDataRaw { get; set; }
// published data
public int PublishedVersionId { get; set; }
@@ -35,5 +36,6 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
public int PubWriterId { get; set; }
public int PubTemplateId { get; set; }
public string PubData { get; set; }
public byte[] PubDataRaw { get; set; }
}
}

View File

@@ -49,6 +49,9 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
.AndSelect<ContentNuDto>("nuEdit", x => Alias(x.Data, "EditData"))
.AndSelect<ContentNuDto>("nuPub", x => Alias(x.Data, "PubData"))
.AndSelect<ContentNuDto>("nuEdit", x => Alias(x.RawData, "EditDataRaw"))
.AndSelect<ContentNuDto>("nuPub", x => Alias(x.RawData, "PubDataRaw"))
.From<NodeDto>();
if (joins != null)
@@ -136,6 +139,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
.AndSelect<ContentDto>(x => Alias(x.ContentTypeId, "ContentTypeId"))
.AndSelect<ContentVersionDto>(x => Alias(x.Id, "VersionId"), x => Alias(x.Text, "EditName"), x => Alias(x.VersionDate, "EditVersionDate"), x => Alias(x.UserId, "EditWriterId"))
.AndSelect<ContentNuDto>("nuEdit", x => Alias(x.Data, "EditData"))
.AndSelect<ContentNuDto>("nuEdit", x => Alias(x.RawData, "EditDataRaw"))
.From<NodeDto>();
if (joins != null)
@@ -211,7 +215,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
if (dto.Edited)
{
if (dto.EditData == null)
if (dto.EditData == null && dto.EditDataRaw == null)
{
if (Debugger.IsAttached)
throw new Exception("Missing cmsContentNu edited content for node " + dto.Id + ", consider rebuilding.");
@@ -219,7 +223,9 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
}
else
{
var nested = _contentNestedDataSerializer.Deserialize(dto.EditData);
var nested = _contentNestedDataSerializer is IContentNestedDataByteSerializer byteSerializer
? byteSerializer.DeserializeBytes(dto.EditDataRaw)
: _contentNestedDataSerializer.Deserialize(dto.EditData);
d = new ContentData
{
@@ -238,7 +244,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
if (dto.Published)
{
if (dto.PubData == null)
if (dto.PubData == null && dto.PubDataRaw == null)
{
if (Debugger.IsAttached)
throw new Exception("Missing cmsContentNu published content for node " + dto.Id + ", consider rebuilding.");
@@ -246,7 +252,9 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
}
else
{
var nested = _contentNestedDataSerializer.Deserialize(dto.PubData);
var nested = _contentNestedDataSerializer is IContentNestedDataByteSerializer byteSerializer
? byteSerializer.DeserializeBytes(dto.PubDataRaw)
: _contentNestedDataSerializer.Deserialize(dto.PubData);
p = new ContentData
{
@@ -279,10 +287,12 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
private ContentNodeKit CreateMediaNodeKit(ContentSourceDto dto)
{
if (dto.EditData == null)
if (dto.EditData == null && dto.EditDataRaw == null)
throw new Exception("No data for media " + dto.Id);
var nested = _contentNestedDataSerializer.Deserialize(dto.EditData);
var nested = _contentNestedDataSerializer is IContentNestedDataByteSerializer byteSerializer
? byteSerializer.DeserializeBytes(dto.EditDataRaw)
: _contentNestedDataSerializer.Deserialize(dto.EditData);
var p = new ContentData
{

View File

@@ -6,9 +6,17 @@ using System.Threading.Tasks;
namespace Umbraco.Web.PublishedCache.NuCache.DataSource
{
// TODO: We need a better name, not sure why the class is called ContentNested in the first place
public interface IContentNestedDataByteSerializer : IContentNestedDataSerializer
{
ContentNestedData DeserializeBytes(byte[] data);
byte[] SerializeBytes(ContentNestedData nestedData);
}
// TODO: We need a better name, not sure why the class is called ContentNested in the first place
public interface IContentNestedDataSerializer
{
ContentNestedData Deserialize(string data);
string Serialize(ContentNestedData nestedData);
ContentNestedData Deserialize(string data);
string Serialize(ContentNestedData nestedData);
}
}

View File

@@ -6,7 +6,7 @@ using System.Collections.Generic;
namespace Umbraco.Web.PublishedCache.NuCache.DataSource
{
internal class MsgPackContentNestedDataSerializer : IContentNestedDataSerializer
internal class MsgPackContentNestedDataSerializer : IContentNestedDataByteSerializer
{
private MessagePackSerializerOptions _options;
@@ -39,8 +39,6 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
return json;
}
// TODO: Instead of returning base64 it would be more ideal to avoid that translation entirely and just store/retrieve raw bytes
public ContentNestedData Deserialize(string data)
{
var bin = Convert.FromBase64String(data);
@@ -54,6 +52,10 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
return Convert.ToBase64String(bin);
}
public ContentNestedData DeserializeBytes(byte[] data) => MessagePackSerializer.Deserialize<ContentNestedData>(data, _options);
public byte[] SerializeBytes(ContentNestedData nestedData) => MessagePackSerializer.Serialize(nestedData, _options);
//private class ContentNestedDataResolver : IFormatterResolver
//{
// // GetFormatter<T>'s get cost should be minimized so use type cache.

View File

@@ -1322,9 +1322,10 @@ namespace Umbraco.Web.PublishedCache.NuCache
var dto = GetDto(content, published);
db.InsertOrUpdate(dto,
"SET data=@data, rv=rv+1 WHERE nodeId=@id AND published=@published",
"SET data=@data, dataRaw=@dataRaw, rv=rv+1 WHERE nodeId=@id AND published=@published",
new
{
dataRaw = dto.RawData,
data = dto.Data,
id = dto.NodeId,
published = dto.Published
@@ -1456,7 +1457,8 @@ namespace Umbraco.Web.PublishedCache.NuCache
{
NodeId = content.Id,
Published = published,
Data = _contentNestedDataSerializer.Serialize(nestedData)
Data = !(_contentNestedDataSerializer is IContentNestedDataByteSerializer) ? _contentNestedDataSerializer.Serialize(nestedData) : null,
RawData = (_contentNestedDataSerializer is IContentNestedDataByteSerializer byteSerializer) ? byteSerializer.SerializeBytes(nestedData) : null
};
//Core.Composing.Current.Logger.Debug<PublishedSnapshotService>(dto.Data);