Skip to content

Commit

Permalink
Removing scoped cache of body aspects (#7523)
Browse files Browse the repository at this point in the history
  • Loading branch information
deanmarcussen authored Nov 5, 2020
1 parent 280471b commit f179e0b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class FacebookPluginPartHandler : ContentPartHandler<FacebookPluginPart>
{
private readonly ILiquidTemplateManager _liquidTemplateManager;
private readonly HtmlEncoder _htmlEncoder;
private HtmlString _bodyAspect;

public FacebookPluginPartHandler(ILiquidTemplateManager liquidTemplateManager, HtmlEncoder htmlEncoder)
{
Expand All @@ -25,12 +24,6 @@ public override Task GetContentItemAspectAsync(ContentItemAspectContext context,
{
return context.ForAsync<BodyAspect>(async bodyAspect =>
{
if (_bodyAspect != null)
{
bodyAspect.Body = _bodyAspect;
return;
}

try
{
var model = new FacebookPluginPartViewModel()
Expand All @@ -43,7 +36,7 @@ public override Task GetContentItemAspectAsync(ContentItemAspectContext context,
var result = await _liquidTemplateManager.RenderAsync(part.Liquid, _htmlEncoder, model,
scope => scope.SetValue("ContentItem", model.ContentItem));

bodyAspect.Body = _bodyAspect = new HtmlString(result);
bodyAspect.Body = new HtmlString(result);
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public class HtmlBodyPartHandler : ContentPartHandler<HtmlBodyPart>
private readonly IShortcodeService _shortcodeService;
private readonly ILiquidTemplateManager _liquidTemplateManager;
private readonly HtmlEncoder _htmlEncoder;
private HtmlString _bodyAspect;
private int _contentItemId;

public HtmlBodyPartHandler(IContentDefinitionManager contentDefinitionManager,
IShortcodeService shortcodeService,
Expand All @@ -38,13 +36,6 @@ public override Task GetContentItemAspectAsync(ContentItemAspectContext context,
{
return context.ForAsync<BodyAspect>(async bodyAspect =>
{
if (bodyAspect != null && part.ContentItem.Id == _contentItemId)
{
bodyAspect.Body = _bodyAspect;

return;
}

try
{
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType);
Expand Down Expand Up @@ -73,13 +64,11 @@ public override Task GetContentItemAspectAsync(ContentItemAspectContext context,
["TypePartDefinition"] = contentTypePartDefinition
});

bodyAspect.Body = _bodyAspect = new HtmlString(html);
_contentItemId = part.ContentItem.Id;
bodyAspect.Body = new HtmlString(html);
}
catch
{
bodyAspect.Body = HtmlString.Empty;
_contentItemId = default;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class LiquidPartHandler : ContentPartHandler<LiquidPart>
{
private readonly ILiquidTemplateManager _liquidTemplateManager;
private readonly HtmlEncoder _htmlEncoder;
private HtmlString _bodyAspect;

public LiquidPartHandler(ILiquidTemplateManager liquidTemplateManager, HtmlEncoder htmlEncoder)
{
Expand All @@ -24,12 +23,6 @@ public override Task GetContentItemAspectAsync(ContentItemAspectContext context,
{
return context.ForAsync<BodyAspect>(async bodyAspect =>
{
if (_bodyAspect != null)
{
bodyAspect.Body = _bodyAspect;
return;
}

try
{
var model = new LiquidPartViewModel()
Expand All @@ -41,7 +34,7 @@ public override Task GetContentItemAspectAsync(ContentItemAspectContext context,
var result = await _liquidTemplateManager.RenderAsync(part.Liquid, _htmlEncoder, model,
scope => scope.SetValue("ContentItem", model.ContentItem));

bodyAspect.Body = _bodyAspect = new HtmlString(result);
bodyAspect.Body = new HtmlString(result);
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public class MarkdownBodyPartHandler : ContentPartHandler<MarkdownBodyPart>
private readonly IHtmlSanitizerService _htmlSanitizerService;
private readonly ILiquidTemplateManager _liquidTemplateManager;
private readonly HtmlEncoder _htmlEncoder;
private HtmlString _bodyAspect;
private int _contentItemId;

public MarkdownBodyPartHandler(IContentDefinitionManager contentDefinitionManager,
IShortcodeService shortcodeService,
Expand All @@ -47,13 +45,6 @@ public override Task GetContentItemAspectAsync(ContentItemAspectContext context,
{
return context.ForAsync<BodyAspect>(async bodyAspect =>
{
if (bodyAspect != null && part.ContentItem.Id == _contentItemId)
{
bodyAspect.Body = _bodyAspect;

return;
}

try
{
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType);
Expand Down Expand Up @@ -91,13 +82,11 @@ public override Task GetContentItemAspectAsync(ContentItemAspectContext context,
html = _htmlSanitizerService.Sanitize(html);
}

bodyAspect.Body = _bodyAspect = new HtmlString(html);
_contentItemId = part.ContentItem.Id;
bodyAspect.Body = new HtmlString(html);
}
catch
{
bodyAspect.Body = HtmlString.Empty;
_contentItemId = default;
}
});
}
Expand Down

0 comments on commit f179e0b

Please sign in to comment.