[Fixes #5596] blueprint harvesting caching (#7549)

Fixes #5596
This commit is contained in:
Carl Woodhouse
2017-02-02 20:23:07 +00:00
committed by Sébastien Ros
parent 2c26c65f63
commit 5a0fe4e105
4 changed files with 7 additions and 8 deletions

View File

@@ -3,5 +3,6 @@
namespace Orchard.Layouts.Framework.Harvesters {
public class HarvestElementsContext {
public IContent Content { get; set; }
public bool IsHarvesting { get; set; }
}
}

View File

@@ -13,7 +13,6 @@ namespace Orchard.Layouts.Providers {
public class BlueprintElementHarvester : Component, IElementHarvester {
private readonly Work<IElementBlueprintService> _elementBlueprintService;
private readonly Work<IElementManager> _elementManager;
private bool _isHarvesting;
public BlueprintElementHarvester(Work<IElementBlueprintService> elementBlueprintService, Work<IElementManager> elementManager) {
_elementBlueprintService = elementBlueprintService;
@@ -21,15 +20,14 @@ namespace Orchard.Layouts.Providers {
}
public IEnumerable<ElementDescriptor> HarvestElements(HarvestElementsContext context) {
if (_isHarvesting)
if (context.IsHarvesting)
return Enumerable.Empty<ElementDescriptor>();
_isHarvesting = true;
var blueprints = _elementBlueprintService.Value.GetBlueprints().ToArray();
var query =
from blueprint in blueprints
let describeContext = new DescribeElementsContext {Content = context.Content, CacheVaryParam = "Blueprints"}
let describeContext = new DescribeElementsContext {Content = context.Content, CacheVaryParam = "Blueprints", IsHarvesting = true }
let baseElementDescriptor = _elementManager.Value.GetElementDescriptorByTypeName(describeContext, blueprint.BaseElementTypeName)
let baseElement = _elementManager.Value.ActivateElement(baseElementDescriptor)
select new ElementDescriptor(
@@ -48,9 +46,7 @@ namespace Orchard.Layouts.Providers {
}
};
var descriptors = query.ToArray();
_isHarvesting = false;
return descriptors;
return query.ToArray();
}
private static string GetCategory(ElementBlueprint blueprint) {

View File

@@ -4,6 +4,7 @@ namespace Orchard.Layouts.Services {
public class DescribeElementsContext {
public IContent Content { get; set; }
public string CacheVaryParam { get; set; }
public bool IsHarvesting { get; set; }
public static readonly DescribeElementsContext Empty = new DescribeElementsContext();
}

View File

@@ -40,7 +40,8 @@ namespace Orchard.Layouts.Services {
var cacheKey = String.Format("LayoutElementTypes-{0}-{1}", contentType ?? "AnyType", context.CacheVaryParam);
return _cacheManager.Get(cacheKey, true, acquireContext => {
var harvesterContext = new HarvestElementsContext {
Content = context.Content
Content = context.Content,
IsHarvesting = context.IsHarvesting
};
var query =
from harvester in _elementHarvesters.Value