Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Default Language to look up base templates. #39

Merged
merged 3 commits into from
Mar 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions Jabberwocky.Glass/Factory/Caching/GlassTemplateCacheService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Glass.Mapper.Sc.Configuration.Attributes;
using Jabberwocky.Glass.Factory.Util;
using Jabberwocky.Glass.Models;
using Sitecore.Data.Managers;

namespace Jabberwocky.Glass.Factory.Caching
{
Expand Down Expand Up @@ -74,18 +75,19 @@ private Type InnerGetImplementingTypeForTemplate(Guid templateId, Type interface
// If no exact match exists, attempt to resolve from 1st-level cache
return _firstLevelCache.GetOrAdd(new Tuple<Type, string>(interfaceType, templateKey), key =>
{
// Otherwise, search for match, and update 1st-level cache
using (var service = _serviceFactory())
{
foreach (Guid baseTemplateId in GetBaseTemplates(service.GetItem<IBaseTemplates>(templateId), service, depth))
{
string templateIdString = baseTemplateId.ToString();
if (itemInterfaces.ContainsKey(templateIdString))
{
return itemInterfaces[templateIdString].ImplementationType;
}
}
}
// Otherwise, search for match, and update 1st-level cache
using (var service = _serviceFactory())
using (new VersionCountDisabler())
{
foreach (Guid baseTemplateId in GetBaseTemplates(service.GetItem<IBaseTemplates>(templateId), service, depth))
{
string templateIdString = baseTemplateId.ToString();
if (itemInterfaces.ContainsKey(templateIdString))
{
return itemInterfaces[templateIdString].ImplementationType;
}
}
}

return null;
});
Expand All @@ -98,14 +100,15 @@ public Type GetFallbackImplementingTypeForTemplate(Guid templateId, Type interfa
return null;
}

using (var service = _serviceFactory())
{
var currentTemplate = service.GetItem<IBaseTemplates>(templateId);
using (var service = _serviceFactory())
using (new VersionCountDisabler())
{
var currentTemplate = service.GetItem<IBaseTemplates>(templateId);

return GetBaseTemplates(currentTemplate, service, depth: MaxDepth)
.Select(guid => InnerGetImplementingTypeForTemplate(guid, interfaceType, 1))
.FirstOrDefault(type => type != null);
}
return GetBaseTemplates(currentTemplate, service, depth: MaxDepth)
.Select(guid => InnerGetImplementingTypeForTemplate(guid, interfaceType, 1))
.FirstOrDefault(type => type != null);
}
}

internal IEnumerable<Guid> GetBaseTemplates(IBaseTemplates item, ISitecoreService service, int depth = DefaultDepth, bool ignoreTemplate = false)
Expand Down