mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Merge pull request #5804 from mvarblow/patch-2
Prevent no-op tasks for taxonomy field updates.
This commit is contained in:
@@ -17,6 +17,8 @@ namespace Orchard.Taxonomies.Handlers {
|
||||
public class TermsPartHandler : ContentHandler {
|
||||
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
private readonly HashSet<int> _processedTermParts = new HashSet<int>();
|
||||
|
||||
public TermsPartHandler(
|
||||
IContentDefinitionManager contentDefinitionManager,
|
||||
@@ -88,12 +90,17 @@ namespace Orchard.Taxonomies.Handlers {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Fires off a processing engine task to run the count processing after the request so it's non-blocking.
|
||||
// Fires off a processing engine task to run the count processing after the request so it's non-blocking.
|
||||
private void RecalculateCount(IProcessingEngine processingEngine, ShellSettings shellSettings, IShellDescriptorManager shellDescriptorManager, TermsPart part) {
|
||||
var termPartRecordIds = part.Terms.Select(t => t.TermRecord.Id).ToArray();
|
||||
processingEngine.AddTask(shellSettings, shellDescriptorManager.GetShellDescriptor(), "ITermCountProcessor.Process", new Dictionary<string, object> { { "termPartRecordIds", termPartRecordIds } });
|
||||
|
||||
if (termPartRecordIds.Any()) {
|
||||
if (!_processedTermParts.Any()) {
|
||||
processingEngine.AddTask(shellSettings, shellDescriptorManager.GetShellDescriptor(), "ITermCountProcessor.Process", new Dictionary<string, object> { { "termPartRecordIds", _processedTermParts } });
|
||||
}
|
||||
foreach (var termPartRecordId in termPartRecordIds) {
|
||||
_processedTermParts.Add(termPartRecordId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Activating(ActivatingContentContext context) {
|
||||
@@ -113,4 +120,4 @@ namespace Orchard.Taxonomies.Handlers {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,6 @@ using Orchard.Events;
|
||||
|
||||
namespace Orchard.Taxonomies.Services {
|
||||
public interface ITermCountProcessor : IEventHandler {
|
||||
void Process(params int[] termPartRecordIds);
|
||||
void Process(IEnumerable<int> termPartRecordIds);
|
||||
}
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ namespace Orchard.Taxonomies.Services {
|
||||
private readonly ShellSettings _shellSettings;
|
||||
private readonly IShellDescriptorManager _shellDescriptorManager;
|
||||
|
||||
private readonly HashSet<int> _processedTermParts = new HashSet<int>();
|
||||
|
||||
public TaxonomyService(
|
||||
IRepository<TermContentItem> termContentItemRepository,
|
||||
@@ -266,9 +267,14 @@ namespace Orchard.Taxonomies.Services {
|
||||
}
|
||||
|
||||
var termPartRecordIds = termList.Select(t => t.Term.TermRecord.Id).ToArray();
|
||||
_processingEngine.AddTask(_shellSettings, _shellDescriptorManager.GetShellDescriptor(), "ITermCountProcessor.Process", new Dictionary<string, object> { { "termPartRecordIds", termPartRecordIds } });
|
||||
|
||||
|
||||
if (termPartRecordIds.Any()) {
|
||||
if (!_processedTermParts.Any()) {
|
||||
_processingEngine.AddTask(_shellSettings, _shellDescriptorManager.GetShellDescriptor(), "ITermCountProcessor.Process", new Dictionary<string, object> { { "termPartRecordIds", _processedTermParts } });
|
||||
}
|
||||
foreach (var termPartRecordId in termPartRecordIds) {
|
||||
_processedTermParts.Add(termPartRecordId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IContentQuery<TermsPart, TermsPartRecord> GetContentItemsQuery(TermPart term, string fieldName = null) {
|
||||
|
@@ -1,3 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Taxonomies.Models;
|
||||
|
||||
@@ -9,20 +13,31 @@ namespace Orchard.Taxonomies.Services {
|
||||
_taxonomyService = taxonomyService;
|
||||
}
|
||||
|
||||
public void Process(params int[] termPartRecordIds) {
|
||||
|
||||
public void Process(IEnumerable<int> termPartRecordIds)
|
||||
{
|
||||
var processedTermPartRecordIds = new List<int>();
|
||||
foreach (var id in termPartRecordIds) {
|
||||
var termPart = _taxonomyService.GetTerm(id);
|
||||
while (termPart != null) {
|
||||
termPart.Count = (int)_taxonomyService.GetContentItemsCount(termPart);
|
||||
|
||||
// compute count for the hierarchy too
|
||||
if (termPart.Container != null) {
|
||||
var parentTerm = termPart.Container.As<TermPart>();
|
||||
termPart = parentTerm;
|
||||
if (!processedTermPartRecordIds.Contains(id)) {
|
||||
var termPart = _taxonomyService.GetTerm(id);
|
||||
if (termPart != null) {
|
||||
ProcessTerm(termPart, processedTermPartRecordIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessTerm(TermPart termPart, ICollection<int> processedTermPartRecordIds)
|
||||
{
|
||||
termPart.Count = (int)_taxonomyService.GetContentItemsCount(termPart);
|
||||
processedTermPartRecordIds.Add(termPart.Id);
|
||||
|
||||
// Look for a parent term that has not yet been processed
|
||||
if (termPart.Container != null) {
|
||||
var parentTerm = termPart.Container.As<TermPart>();
|
||||
if (parentTerm != null && !processedTermPartRecordIds.Contains(parentTerm.Id)) {
|
||||
ProcessTerm(parentTerm, processedTermPartRecordIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user