U4-5174 - The IContentType model should not hold direct references to ITemplates

Created by Shannon Deminick 03 Jul 2014, 07:34:51 Updated by Shannon Deminick 02 Jun 2015, 19:00:11

Subtask of: U4-5482

Currently the IContentType Model returns an ITemplate instance for the DefaultTemplate property and then returns a collection of IEnumerable for the AllowedTemplates property but here's the problem with that:

When we cache an entity we cache the whole entity, this means that the ITemplate's associated with each IContentType are also cached, this means there's cache on cache and also means that we have to manage more cache references. The next problem is that each ITemplate also references an ITemplate as it's master - so again this can add even more cache just to the single IContentType. If we go a step further and think that there probably other IContentType's references the same ITemplates, then we're caching even more of the same object. But wait... when we lookup the same ITemplate from the TemplateRepository, we are again caching the same ITemplate on top of all of this.

The IContentType model should only expose a very simple model to reference the template - to display a content type in the back office we really only need the template id and it's alias and we can easily include all of this data in a single request whereas currently for each template we are looking each one up individually using the TemplateRepository.

I think there may be a way to fix all of this without introducing a true 'breaking change'. We cannot remove the properties from IContentType:

ITemplate DefaultTemplate { get; } IEnumerable AllowedTemplates { get; set; }

since that would be really breaking, but we could add 2 new properties (since we are allowed to do that):

TemplateDefinition DefaultTemplateDefinition {get; } IEnumerable AllowedTemplateDefinitions { get; set; }

a TemplateDefinition is just an Id + Alias model (we can of course name this however we feel).

Then we mark DefaultTemplate and AllowedTemplates as obsolete and in our ContentType instance we can have it contain logic to go lookup the true template definitions with the ApplicationContext - this isn't ideal but there's no way around that without really breaking stuff. We'd also ensure that when caching the IContentType that these now obsolete properties are ignored.

Comments

Shannon Deminick 03 Jul 2014, 08:21:51

We need to determine which other models need to be decoupled, not all of them need to be but anything with recursion or anything that doesn't rely specifically on another model needs to be refactored.


Shannon Deminick 28 Aug 2014, 23:04:31

Maybe we can do declarative runtime object caching, basically we should be able to not cache specific parts of an entity (i.e. anything recursive or not required on the object or that is already cached elsewhere as an entity), then in the repositories when resolving an item from the cache, we can re-set this data on to the entity.


Dan Booth 14 May 2015, 20:04:45

@Shandem How are we to get the DefaultTemplate currently? When I call ContentTypeService.GetAllContentTypes() it returns a list of ContentTypes, but the DefaultTemplate property is always null. How do I get a reference to it? I'm using 7.2.4


Shannon Deminick 02 Jun 2015, 19:00:11

If you can replicate that everytime it's probably a bug, are you able to create one ?


Priority: Normal

Type: Bug

State: Open

Assignee: Shannon Deminick

Difficulty: Normal

Category:

Backwards Compatible: False

Fix Submitted:

Affected versions:

Due in version: 8.0.0

Sprint:

Story Points:

Cycle: