Skip to content

Commit 40dbfa7

Browse files
authored
Merge pull request #8376 from umbraco/v8/feature/nucache-perf
Performance improvements mainly around front-end caching
2 parents ec65a6c + 94d525d commit 40dbfa7

File tree

81 files changed

+2192
-317
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+2192
-317
lines changed

build/NuSpecs/UmbracoCms.Web.nuspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<dependency id="Microsoft.Owin.Security.OAuth" version="[4.0.1,4.999999)" />
4444
<dependency id="System.Threading.Tasks.Dataflow" version="[4.9.0,4.999999)" />
4545
<dependency id="System.Text.Encoding.CodePages" version="[4.7.1,4.999999)" />
46+
<dependency id="MessagePack" version="[2.1.165,2.999999)" />
4647

4748
</group>
4849

src/Umbraco.Core/Composing/Current.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace Umbraco.Core.Composing
3030
public static class Current
3131
{
3232
private static IFactory _factory;
33+
private static IRuntimeState _state;
3334

3435
// TODO: get rid of these oddities
3536
// we don't want Umbraco tests to die because the container has not been properly initialized,
@@ -125,7 +126,17 @@ public static IProfilingLogger ProfilingLogger
125126
?? new ProfilingLogger(Logger, Profiler);
126127

127128
public static IRuntimeState RuntimeState
128-
=> Factory.GetInstance<IRuntimeState>();
129+
{
130+
get
131+
{
132+
return _state ?? Factory.GetInstance<IRuntimeState>();
133+
}
134+
internal set
135+
{
136+
// this is only used when the boot entirely fails, we need to manually set this so we can report
137+
_state = value;
138+
}
139+
}
129140

130141
public static TypeLoader TypeLoader
131142
=> Factory.GetInstance<TypeLoader>();

src/Umbraco.Core/Constants-SqlTemplates.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ public static class DataTypeRepository
2424
{
2525
public const string EnsureUniqueNodeName = "Umbraco.Core.DataTypeDefinitionRepository.EnsureUniqueNodeName";
2626
}
27+
28+
internal static class NuCacheDatabaseDataSource
29+
{
30+
public const string WhereNodeId = "Umbraco.Web.PublishedCache.NuCache.DataSource.WhereNodeId";
31+
public const string WhereNodeIdX = "Umbraco.Web.PublishedCache.NuCache.DataSource.WhereNodeIdX";
32+
public const string SourcesSelectUmbracoNodeJoin = "Umbraco.Web.PublishedCache.NuCache.DataSource.SourcesSelectUmbracoNodeJoin";
33+
public const string ContentSourcesSelect = "Umbraco.Web.PublishedCache.NuCache.DataSource.ContentSourcesSelect";
34+
public const string ContentSourcesCount = "Umbraco.Web.PublishedCache.NuCache.DataSource.ContentSourcesCount";
35+
public const string MediaSourcesSelect = "Umbraco.Web.PublishedCache.NuCache.DataSource.MediaSourcesSelect";
36+
public const string MediaSourcesCount = "Umbraco.Web.PublishedCache.NuCache.DataSource.MediaSourcesCount";
37+
public const string ObjectTypeNotTrashedFilter = "Umbraco.Web.PublishedCache.NuCache.DataSource.ObjectTypeNotTrashedFilter";
38+
public const string OrderByLevelIdSortOrder = "Umbraco.Web.PublishedCache.NuCache.DataSource.OrderByLevelIdSortOrder";
39+
40+
}
2741
}
2842
}
2943
}

src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Umbraco.Core.Migrations.Upgrade.V_8_6_0;
1010
using Umbraco.Core.Migrations.Upgrade.V_8_9_0;
1111
using Umbraco.Core.Migrations.Upgrade.V_8_10_0;
12+
using Umbraco.Core.Migrations.Upgrade.V_8_15_0;
1213

1314
namespace Umbraco.Core.Migrations.Upgrade
1415
{
@@ -198,10 +199,14 @@ protected void DefinePlan()
198199

199200
// to 8.9.0
200201
To<ExternalLoginTableUserData>("{B5838FF5-1D22-4F6C-BCEB-F83ACB14B575}");
201-
202+
202203
// to 8.10.0
203204
To<AddPropertyTypeLabelOnTopColumn>("{D6A8D863-38EC-44FB-91EC-ACD6A668BD18}");
204205

206+
// to 8.15.0...
207+
To<AddCmsContentNuByteColumn>("{8DDDCD0B-D7D5-4C97-BD6A-6B38CA65752F}");
208+
To<UpgradedIncludeIndexes>("{4695D0C9-0729-4976-985B-048D503665D8}");
209+
205210
//FINAL
206211
}
207212
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Linq;
2+
using Umbraco.Core.Persistence.Dtos;
3+
4+
namespace Umbraco.Core.Migrations.Upgrade.V_8_15_0
5+
{
6+
public class AddCmsContentNuByteColumn : MigrationBase
7+
{
8+
public AddCmsContentNuByteColumn(IMigrationContext context)
9+
: base(context)
10+
{
11+
12+
}
13+
14+
public override void Migrate()
15+
{
16+
var columns = SqlSyntax.GetColumnsInSchema(Context.Database).ToList();
17+
18+
AddColumnIfNotExists<ContentNuDto>(columns, "dataRaw");
19+
}
20+
}
21+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System.Linq;
2+
using Umbraco.Core.Migrations.Expressions.Execute.Expressions;
3+
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
4+
using Umbraco.Core.Persistence.Dtos;
5+
6+
namespace Umbraco.Core.Migrations.Upgrade.V_8_15_0
7+
{
8+
public class UpgradedIncludeIndexes : MigrationBase
9+
{
10+
public UpgradedIncludeIndexes(IMigrationContext context)
11+
: base(context)
12+
{
13+
14+
}
15+
16+
public override void Migrate()
17+
{
18+
// Need to drop the FK for the redirect table before modifying the unique id index
19+
Delete.ForeignKey()
20+
.FromTable(Constants.DatabaseSchema.Tables.RedirectUrl)
21+
.ForeignColumn("contentKey")
22+
.ToTable(NodeDto.TableName)
23+
.PrimaryColumn("uniqueID")
24+
.Do();
25+
var nodeDtoIndexes = new[] { $"IX_{NodeDto.TableName}_UniqueId", $"IX_{NodeDto.TableName}_ObjectType", $"IX_{NodeDto.TableName}_Level" };
26+
DeleteIndexes<NodeDto>(nodeDtoIndexes); // delete existing ones
27+
CreateIndexes<NodeDto>(nodeDtoIndexes); // update/add
28+
// Now re-create the FK for the redirect table
29+
Create.ForeignKey()
30+
.FromTable(Constants.DatabaseSchema.Tables.RedirectUrl)
31+
.ForeignColumn("contentKey")
32+
.ToTable(NodeDto.TableName)
33+
.PrimaryColumn("uniqueID")
34+
.Do();
35+
36+
37+
var contentVersionIndexes = new[] { $"IX_{ContentVersionDto.TableName}_NodeId", $"IX_{ContentVersionDto.TableName}_Current" };
38+
DeleteIndexes<ContentVersionDto>(contentVersionIndexes); // delete existing ones
39+
CreateIndexes<ContentVersionDto>(contentVersionIndexes); // update/add
40+
}
41+
42+
private void DeleteIndexes<T>(params string[] toDelete)
43+
{
44+
var tableDef = DefinitionFactory.GetTableDefinition(typeof(T), Context.SqlContext.SqlSyntax);
45+
46+
foreach (var i in toDelete)
47+
if (IndexExists(i))
48+
Delete.Index(i).OnTable(tableDef.Name).Do();
49+
50+
}
51+
52+
private void CreateIndexes<T>(params string[] toCreate)
53+
{
54+
var tableDef = DefinitionFactory.GetTableDefinition(typeof(T), Context.SqlContext.SqlSyntax);
55+
56+
foreach (var c in toCreate)
57+
{
58+
// get the definition by name
59+
var index = tableDef.Indexes.First(x => x.Name == c);
60+
new ExecuteSqlStatementExpression(Context) { SqlStatement = Context.SqlContext.SqlSyntax.Format(index) }.Execute();
61+
}
62+
63+
}
64+
}
65+
}

src/Umbraco.Core/Models/IContentBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Umbraco.Core.Models
66
{
7+
78
/// <summary>
89
/// Provides a base class for content items.
910
/// </summary>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
3+
namespace Umbraco.Core.Models
4+
{
5+
public interface IReadOnlyContentBase
6+
{
7+
/// <summary>
8+
/// Gets the integer identifier of the entity.
9+
/// </summary>
10+
int Id { get; }
11+
12+
/// <summary>
13+
/// Gets the Guid unique identifier of the entity.
14+
/// </summary>
15+
Guid Key { get; }
16+
17+
/// <summary>
18+
/// Gets the creation date.
19+
/// </summary>
20+
DateTime CreateDate { get; }
21+
22+
/// <summary>
23+
/// Gets the last update date.
24+
/// </summary>
25+
DateTime UpdateDate { get; }
26+
27+
/// <summary>
28+
/// Gets the name of the entity.
29+
/// </summary>
30+
string Name { get; }
31+
32+
/// <summary>
33+
/// Gets the identifier of the user who created this entity.
34+
/// </summary>
35+
int CreatorId { get; }
36+
37+
/// <summary>
38+
/// Gets the identifier of the parent entity.
39+
/// </summary>
40+
int ParentId { get; }
41+
42+
/// <summary>
43+
/// Gets the level of the entity.
44+
/// </summary>
45+
int Level { get; }
46+
47+
/// <summary>
48+
/// Gets the path to the entity.
49+
/// </summary>
50+
string Path { get; }
51+
52+
/// <summary>
53+
/// Gets the sort order of the entity.
54+
/// </summary>
55+
int SortOrder { get; }
56+
57+
/// <summary>
58+
/// Gets the content type id
59+
/// </summary>
60+
int ContentTypeId { get; }
61+
62+
/// <summary>
63+
/// Gets the identifier of the writer.
64+
/// </summary>
65+
int WriterId { get; }
66+
67+
/// <summary>
68+
/// Gets the version identifier.
69+
/// </summary>
70+
int VersionId { get; }
71+
}
72+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
3+
namespace Umbraco.Core.Models
4+
{
5+
internal struct ReadOnlyContentBaseAdapter : IReadOnlyContentBase
6+
{
7+
private readonly IContentBase _content;
8+
9+
private ReadOnlyContentBaseAdapter(IContentBase content)
10+
{
11+
_content = content ?? throw new ArgumentNullException(nameof(content));
12+
}
13+
14+
public static ReadOnlyContentBaseAdapter Create(IContentBase content) => new ReadOnlyContentBaseAdapter(content);
15+
16+
public int Id => _content.Id;
17+
18+
public Guid Key => _content.Key;
19+
20+
public DateTime CreateDate => _content.CreateDate;
21+
22+
public DateTime UpdateDate => _content.UpdateDate;
23+
24+
public string Name => _content.Name;
25+
26+
public int CreatorId => _content.CreatorId;
27+
28+
public int ParentId => _content.ParentId;
29+
30+
public int Level => _content.Level;
31+
32+
public string Path => _content.Path;
33+
34+
public int SortOrder => _content.SortOrder;
35+
36+
public int ContentTypeId => _content.ContentTypeId;
37+
38+
public int WriterId => _content.WriterId;
39+
40+
public int VersionId => _content.VersionId;
41+
}
42+
}

src/Umbraco.Core/Persistence/DatabaseAnnotations/IndexAttribute.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,10 @@ public IndexAttribute(IndexTypes indexType)
3131
/// Gets or sets the column name(s) for the current index
3232
/// </summary>
3333
public string ForColumns { get; set; }
34+
35+
/// <summary>
36+
/// Gets or sets the column name(s) for the columns to include in the index
37+
/// </summary>
38+
public string IncludeColumns { get; set; }
3439
}
3540
}

0 commit comments

Comments
 (0)