mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +08:00
Update TermCountProcessor.cs
Don't process the same term multiple times if it happens to be the parent of multiple terms on the list.
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.Taxonomies.Models;
|
using Orchard.Taxonomies.Models;
|
||||||
|
|
||||||
@@ -9,20 +13,31 @@ namespace Orchard.Taxonomies.Services {
|
|||||||
_taxonomyService = taxonomyService;
|
_taxonomyService = taxonomyService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Process(params int[] termPartRecordIds) {
|
public void Process(IEnumerable<int> termPartRecordIds)
|
||||||
|
{
|
||||||
|
var processedTermPartRecordIds = new List<int>();
|
||||||
foreach (var id in termPartRecordIds) {
|
foreach (var id in termPartRecordIds) {
|
||||||
var termPart = _taxonomyService.GetTerm(id);
|
if (!processedTermPartRecordIds.Contains(id)) {
|
||||||
while (termPart != null) {
|
var termPart = _taxonomyService.GetTerm(id);
|
||||||
termPart.Count = (int)_taxonomyService.GetContentItemsCount(termPart);
|
if (termPart != null) {
|
||||||
|
ProcessTerm(termPart, processedTermPartRecordIds);
|
||||||
// compute count for the hierarchy too
|
|
||||||
if (termPart.Container != null) {
|
|
||||||
var parentTerm = termPart.Container.As<TermPart>();
|
|
||||||
termPart = parentTerm;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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