U4-9617 - Performance: Anytime a document is visited in the back office that has a Pending version a full IContent lookup is done just to check for the published version date

Created by Shannon Deminick 09 Mar 2017, 18:08:37 Updated by Shannon Deminick 21 Jun 2017, 07:26:48

Relates to: U4-9615

Subtask of: U4-9609

We don't need to lookup an entire IContent object just to check it's date, we should have a very very fast method to just get a content item's status dates (i.e. newest and published), or even a simple method to get the version information for a content item - it's published and newest version (GUID) and their dates.


Stephan 23 Mar 2017, 16:25:26

Notes: in ContentModelMapper.GetPublishedDate, if the document is not published and has a published version, we get a full version just to get its UpdateDate. Not needed esp. considering that whenever we load a content, if it's not published, we also join to find the published versionId, so we could get the date as well.

Stephan 23 Mar 2017, 17:01:41

PR https://github.com/umbraco/Umbraco-CMS/pull/1824

what it does: add internal property Content.PublishedDate and load it along PublishedVersionGuid (which was loaded already) at basically no cost. use that property in ContentModelMapper instead of doing a db access. property is a DateTime with value default(DateTime) when not published, to be consistent with PublishedVersionGuid which has value default(Guid) when not published.

review: code review + edit content w/ browser tools open, inspect the result of GetById request, json property publishDate should contain either null (not published) or the actual publish date. the "unpublish" option in the "save" button should appear only for published content. and that should work including when publishing / unpublishing.

Shannon Deminick 29 Mar 2017, 05:28:32

Brilliant, this is great.

Mirko Matytschak 24 May 2017, 15:04:50

@zpqrtbnk This solution is actually not so brilliant as it appears at first glance. You nail down an IContent to always be a Content. If you ever want to write classes implementing IContent which are not the Content class, you'll get trouble here. This is, what we are doing for a specific purpose. We implement IContent in an own class in order to convert it to a ContentItemDisplay so that we can use the Umbraco client side code to view and edit our own entities.

Your fix should have included PublishedDate into the IContent interface or to mix it in from a new interface, if IContent can't be changed:

interface IPublishable { DateTime ? PublishedDate {get;set;} } class Content : IContent, IPublishable { DateTime ? PublishedDate { // Implementation } }

That way you don't need a cast to Content, but only a cast to IPublishable to get the date.

@Shandem: If you agree with this suggestion I'd prepare a pull request.

Shannon Deminick 21 Jun 2017, 07:26:48

This decision was made because this was a patch version release and we didn't want to break the interface for that.

For 7.7 we can add PublishedDate to IContent if you wish to create a PR for that and target the dev-v7.7 branch?

Priority: Normal

Type: Bug

State: Fixed


Difficulty: Normal


Backwards Compatible: True

Fix Submitted:

Affected versions:

Due in version: 7.5.12

Sprint: Sprint 55

Story Points: 1