mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-26 03:40:56 +08:00
Only query database if a new tag is being added. (#7845)
This commit is contained in:
@@ -191,20 +191,22 @@ namespace Orchard.Tags.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateTagsForContentItem(ContentItem contentItem, IEnumerable<string> tagNamesForContentItem) {
|
public void UpdateTagsForContentItem(ContentItem contentItem, IEnumerable<string> tagNamesForContentItem) {
|
||||||
var tags = tagNamesForContentItem.Select(CreateTag);
|
var newTagsForContentItem = tagNamesForContentItem.Where(s => s != null).ToList();
|
||||||
var newTagsForContentItem = new List<TagRecord>(tags);
|
|
||||||
var currentTagsForContentItem = contentItem.As<TagsPart>().Record.Tags;
|
var currentTagsForContentItem = contentItem.As<TagsPart>().Record.Tags;
|
||||||
|
|
||||||
foreach (var tagContentItem in currentTagsForContentItem) {
|
foreach (var tagContentItem in currentTagsForContentItem) {
|
||||||
if (!newTagsForContentItem.Contains(tagContentItem.TagRecord)) {
|
var newTag = newTagsForContentItem.FirstOrDefault(t => t.Equals(tagContentItem.TagRecord.TagName, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
if (newTag == null) {
|
||||||
_contentTagRepository.Delete(tagContentItem);
|
_contentTagRepository.Delete(tagContentItem);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
newTagsForContentItem.Remove(tagContentItem.TagRecord);
|
newTagsForContentItem.Remove(newTag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var newTagForContentItem in newTagsForContentItem) {
|
foreach (var newTagForContentItem in newTagsForContentItem) {
|
||||||
_contentTagRepository.Create(new ContentTagRecord { TagsPartRecord = contentItem.As<TagsPart>().Record, TagRecord = newTagForContentItem });
|
_contentTagRepository.Create(new ContentTagRecord { TagsPartRecord = contentItem.As<TagsPart>().Record, TagRecord = CreateTag(newTagForContentItem) });
|
||||||
}
|
}
|
||||||
|
|
||||||
contentItem.As<TagsPart>().CurrentTags = tagNamesForContentItem;
|
contentItem.As<TagsPart>().CurrentTags = tagNamesForContentItem;
|
||||||
|
|||||||
Reference in New Issue
Block a user