diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs index 8b9342a3ba..384091e316 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs @@ -960,8 +960,8 @@ ORDER BY cmsContentVersion.id DESC publishedDataCollection.Add(publishedDto); } - - var content = new List(); + //This is a tuple list identifying if the content item came from the cache or not + var content = new List>(); var defs = new DocumentDefinitionCollection(includeAllVersions); var templateIds = new List(); @@ -982,7 +982,7 @@ ORDER BY cmsContentVersion.id DESC //only use this cached version if the dto returned is also the publish version, they must match and be teh same version if (cached != null && cached.Version == dto.VersionId && cached.Published && dto.Published) { - content.Add(cached); + content.Add(new Tuple(cached, true)); continue; } } @@ -1008,7 +1008,7 @@ ORDER BY cmsContentVersion.id DESC if (dto.TemplateId.HasValue && dto.TemplateId.Value > 0) templateIds.Add(dto.TemplateId.Value); - content.Add(ContentFactory.BuildEntity(dto, contentType, publishedDto)); + content.Add(new Tuple(ContentFactory.BuildEntity(dto, contentType, publishedDto), false)); } } @@ -1020,8 +1020,14 @@ ORDER BY cmsContentVersion.id DESC var propertyData = GetPropertyCollection(pagingSqlQuery, defs); // assign template and property data - foreach (var cc in content) + foreach (var contentItem in content) { + var cc = contentItem.Item1; + var fromCache = contentItem.Item2; + + //if this has come from cache, we do not need to build up it's structure + if (fromCache) continue; + var def = defs[includeAllVersions ? (ValueType)cc.Version : cc.Id]; ITemplate template = null; @@ -1033,9 +1039,9 @@ ORDER BY cmsContentVersion.id DESC //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 cc.ResetDirtyProperties(false); - } + } - return content; + return content.Select(x => x.Item1).ToArray(); } /// diff --git a/src/Umbraco.Core/Persistence/Repositories/MediaRepository.cs b/src/Umbraco.Core/Persistence/Repositories/MediaRepository.cs index 2278970f26..fc4f8432d1 100644 --- a/src/Umbraco.Core/Persistence/Repositories/MediaRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/MediaRepository.cs @@ -164,7 +164,9 @@ namespace Umbraco.Core.Persistence.Repositories { // fetch returns a list so it's ok to iterate it in this method var dtos = Database.Fetch(sqlFull); - var content = new List(); + + //This is a tuple list identifying if the content item came from the cache or not + var content = new List>(); var defs = new DocumentDefinitionCollection(); //track the looked up content types, even though the content types are cached @@ -182,7 +184,7 @@ namespace Umbraco.Core.Persistence.Repositories //store different versions, but just in case someone corrupts some data we'll double check to be sure. if (cached != null && cached.Version == dto.VersionId) { - content.Add(cached); + content.Add(new Tuple(cached, true)); continue; } } @@ -204,7 +206,7 @@ namespace Umbraco.Core.Persistence.Repositories // track the definition and if it's successfully added or updated then processed if (defs.AddOrUpdate(new DocumentDefinition(dto, contentType))) { - content.Add(MediaFactory.BuildEntity(dto, contentType)); + content.Add(new Tuple(MediaFactory.BuildEntity(dto, contentType), false)); } } @@ -212,16 +214,22 @@ namespace Umbraco.Core.Persistence.Repositories var propertyData = GetPropertyCollection(pagingSqlQuery, defs); // assign property data - foreach (var cc in content) + foreach (var contentItem in content) { + var cc = contentItem.Item1; + var fromCache = contentItem.Item2; + + //if this has come from cache, we do not need to build up it's structure + if (fromCache) continue; + cc.Properties = propertyData[cc.Version]; //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 cc.ResetDirtyProperties(false); - } + } - return content; + return content.Select(x => x.Item1).ToArray(); } public override IMedia GetByVersion(Guid versionId) diff --git a/src/Umbraco.Core/Persistence/Repositories/MemberRepository.cs b/src/Umbraco.Core/Persistence/Repositories/MemberRepository.cs index 9d01e195c7..9d451a3066 100644 --- a/src/Umbraco.Core/Persistence/Repositories/MemberRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/MemberRepository.cs @@ -681,7 +681,8 @@ namespace Umbraco.Core.Persistence.Repositories // fetch returns a list so it's ok to iterate it in this method var dtos = Database.Fetch(sqlFull); - var content = new List(); + //This is a tuple list identifying if the content item came from the cache or not + var content = new List>(); var defs = new DocumentDefinitionCollection(); foreach (var dto in dtos) @@ -694,7 +695,7 @@ namespace Umbraco.Core.Persistence.Repositories //store different versions, but just in case someone corrupts some data we'll double check to be sure. if (cached != null && cached.Version == dto.ContentVersionDto.VersionId) { - content.Add(cached); + content.Add(new Tuple(cached, true)); continue; } } @@ -706,7 +707,7 @@ namespace Umbraco.Core.Persistence.Repositories // need properties if (defs.AddOrUpdate(new DocumentDefinition(dto.ContentVersionDto, contentType))) { - content.Add(MemberFactory.BuildEntity(dto, contentType)); + content.Add(new Tuple(MemberFactory.BuildEntity(dto, contentType), false)); } } @@ -714,8 +715,14 @@ namespace Umbraco.Core.Persistence.Repositories var propertyData = GetPropertyCollection(pagingSqlQuery, defs); // assign property data - foreach (var cc in content) + foreach (var contentItem in content) { + var cc = contentItem.Item1; + var fromCache = contentItem.Item2; + + //if this has come from cache, we do not need to build up it's structure + if (fromCache) continue; + cc.Properties = propertyData[cc.Version]; //on initial construction we don't want to have dirty properties tracked @@ -723,7 +730,7 @@ namespace Umbraco.Core.Persistence.Repositories cc.ResetDirtyProperties(false); } - return content; + return content.Select(x => x.Item1).ToArray(); } /// diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index 32665910ad..44e91e2b80 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -2185,6 +2185,7 @@ namespace Umbraco.Core.Services //We need to check if children and their publish state to ensure that we 'republish' content that was previously published if (published && previouslyPublished == false && HasChildren(content.Id)) { + //TODO: Horrible for performance if there are lots of descendents! We should page if anything but this is crazy var descendants = GetPublishedDescendants(content); _publishingStrategy.PublishingFinalized(descendants, false);