From 39625d94ddeb6fab6e5a5ce64aa369ea17e7352d Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 3 Jul 2020 15:41:25 +1000 Subject: [PATCH] Adds migration for binary column on cmsContentNu --- .../Migrations/Upgrade/UmbracoPlan.cs | 3 ++- .../V_8_7_0/AddCmsContentNuByteColumn.cs | 21 ++++++++++++++++++ .../Persistence/Dtos/ContentNuDto.cs | 5 +++++ src/Umbraco.Core/Umbraco.Core.csproj | 1 + .../NuCache/DataSource/ContentSourceDto.cs | 2 ++ .../NuCache/DataSource/DatabaseDataSource.cs | 22 ++++++++++++++----- .../IContentNestedDataSerializer.cs | 12 ++++++++-- .../MsgPackContentNestedDataSerializer.cs | 8 ++++--- .../NuCache/PublishedSnapshotService.cs | 6 +++-- 9 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 src/Umbraco.Core/Migrations/Upgrade/V_8_7_0/AddCmsContentNuByteColumn.cs diff --git a/src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs b/src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs index f0cfc08281..4a4260b683 100644 --- a/src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs +++ b/src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs @@ -191,8 +191,9 @@ namespace Umbraco.Core.Migrations.Upgrade To("{EE288A91-531B-4995-8179-1D62D9AA3E2E}"); To("{2AB29964-02A1-474D-BD6B-72148D2A53A2}"); - + // to 8.7.0... To("{a78e3369-8ea3-40ec-ad3f-5f76929d2b20}"); + To("{8DDDCD0B-D7D5-4C97-BD6A-6B38CA65752F}"); //FINAL } diff --git a/src/Umbraco.Core/Migrations/Upgrade/V_8_7_0/AddCmsContentNuByteColumn.cs b/src/Umbraco.Core/Migrations/Upgrade/V_8_7_0/AddCmsContentNuByteColumn.cs new file mode 100644 index 0000000000..3cb51afb99 --- /dev/null +++ b/src/Umbraco.Core/Migrations/Upgrade/V_8_7_0/AddCmsContentNuByteColumn.cs @@ -0,0 +1,21 @@ +using System.Linq; +using Umbraco.Core.Persistence.Dtos; + +namespace Umbraco.Core.Migrations.Upgrade.V_8_6_0 +{ + public class AddCmsContentNuByteColumn : MigrationBase + { + public AddCmsContentNuByteColumn(IMigrationContext context) + : base(context) + { + + } + + public override void Migrate() + { + var columns = SqlSyntax.GetColumnsInSchema(Context.Database).ToList(); + + AddColumnIfNotExists(columns, "dataRaw"); + } + } +} diff --git a/src/Umbraco.Core/Persistence/Dtos/ContentNuDto.cs b/src/Umbraco.Core/Persistence/Dtos/ContentNuDto.cs index c6269d5317..664d188a10 100644 --- a/src/Umbraco.Core/Persistence/Dtos/ContentNuDto.cs +++ b/src/Umbraco.Core/Persistence/Dtos/ContentNuDto.cs @@ -25,8 +25,13 @@ namespace Umbraco.Core.Persistence.Dtos /// [Column("data")] [SpecialDbType(SpecialDbTypes.NTEXT)] + [NullSetting(NullSetting = NullSettings.Null)] public string Data { get; set; } + [Column("dataRaw")] + [NullSetting(NullSetting = NullSettings.Null)] + public byte[] RawData { get; set; } + [Column("rv")] public long Rv { get; set; } } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index c5a953631a..706c2a3650 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -132,6 +132,7 @@ + diff --git a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/ContentSourceDto.cs b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/ContentSourceDto.cs index 37fb9df8bb..be2f9921d1 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/ContentSourceDto.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/ContentSourceDto.cs @@ -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; } } } diff --git a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/DatabaseDataSource.cs b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/DatabaseDataSource.cs index e39f649eaf..48ff3e558c 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/DatabaseDataSource.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/DatabaseDataSource.cs @@ -49,6 +49,9 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource .AndSelect("nuEdit", x => Alias(x.Data, "EditData")) .AndSelect("nuPub", x => Alias(x.Data, "PubData")) + .AndSelect("nuEdit", x => Alias(x.RawData, "EditDataRaw")) + .AndSelect("nuPub", x => Alias(x.RawData, "PubDataRaw")) + .From(); if (joins != null) @@ -136,6 +139,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource .AndSelect(x => Alias(x.ContentTypeId, "ContentTypeId")) .AndSelect(x => Alias(x.Id, "VersionId"), x => Alias(x.Text, "EditName"), x => Alias(x.VersionDate, "EditVersionDate"), x => Alias(x.UserId, "EditWriterId")) .AndSelect("nuEdit", x => Alias(x.Data, "EditData")) + .AndSelect("nuEdit", x => Alias(x.RawData, "EditDataRaw")) .From(); 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 { diff --git a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/IContentNestedDataSerializer.cs b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/IContentNestedDataSerializer.cs index d9e2702d08..edd061fbe4 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/IContentNestedDataSerializer.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/IContentNestedDataSerializer.cs @@ -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); } } diff --git a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/MsgPackContentNestedDataSerializer.cs b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/MsgPackContentNestedDataSerializer.cs index 99a306fecb..1a093292b5 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/MsgPackContentNestedDataSerializer.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/MsgPackContentNestedDataSerializer.cs @@ -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(data, _options); + + public byte[] SerializeBytes(ContentNestedData nestedData) => MessagePackSerializer.Serialize(nestedData, _options); + //private class ContentNestedDataResolver : IFormatterResolver //{ // // GetFormatter's get cost should be minimized so use type cache. diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs index 6289667d3b..99396b45c9 100755 --- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs @@ -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(dto.Data);