diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs index 953228c3ff67..d65c05660c3c 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs @@ -186,6 +186,9 @@ protected virtual void DefinePlan() To("{D7E8F9A0-B1C2-4D3E-A5F6-7890ABCDEF12}"); To("{3F9B6A1C-7D84-4E2B-9C15-6A2E8F3D5B47}"); + // To 17.6.0 + To("{3A1A8047-74AE-491A-B2C4-0BAE4A1289EC}"); + // To 18.0.0 // TODO (V18): Enable on 18 branch //// To("{74332C49-B279-4945-8943-F8F00B1F5949}"); diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_17_6_0/AddContentTypeIdIndexForContent.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_17_6_0/AddContentTypeIdIndexForContent.cs new file mode 100644 index 000000000000..8bbc4b503e9f --- /dev/null +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_17_6_0/AddContentTypeIdIndexForContent.cs @@ -0,0 +1,41 @@ +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using Umbraco.Cms.Infrastructure.Persistence.Dtos; + +namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_17_6_0; + +/// +/// Adds an index on the contentTypeId column of the umbracoContent table to support efficient +/// content-type-scoped queries (e.g. the content cache rebuild triggered by content type changes). +/// +public class AddContentTypeIdIndexForContent : AsyncMigrationBase +{ + private const string IndexName = "IX_" + ContentDto.TableName + "_" + ContentDto.ContentTypeIdColumnName; + + /// + /// Initializes a new instance of the class. + /// + /// The migration context. + public AddContentTypeIdIndexForContent(IMigrationContext context) + : base(context) + { + } + + /// + protected override Task MigrateAsync() + { + if (IndexExists(IndexName)) + { + return Task.CompletedTask; + } + + // Give scope for the migration to complete within the command timeout, which may be necessary on large datasets. + EnsureLongCommandTimeout(Database); + + // Create the index from the definition on ContentDto, so it matches a fresh install exactly. + CreateIndex(IndexName); + + return Task.CompletedTask; + } +} diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentDto.cs index a7c7e9ae92df..b62dcb897285 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentDto.cs @@ -29,6 +29,7 @@ public class ContentDto /// [Column(ContentTypeIdColumnName)] [ForeignKey(typeof(ContentTypeDto), Column = ContentTypeDto.NodeIdColumnName)] + [Index(IndexTypes.NonClustered, Name = "IX_" + TableName + "_" + ContentTypeIdColumnName)] public int ContentTypeId { get; set; } ///