mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +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.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