Skip to content

Commit f77cf59

Browse files
committed
Accounted for Topic.References on Delete()
Previously, the `TopicRepository`'s base `Delete()` class accounted for `Topic.Relationships` by removing any outgoing or incoming relationships that would be affected by the operation, thus ensuring that no orphaned topic references were persisted in memory from other parts of the topic graph. This helps ensure there aren't any legacy references maintained in the cache after a delete. While this accounted for `Topic.Relationships`, however, it didn't account for the new `Topic.References`. This is corrected in this update.
1 parent 213a46b commit f77cf59

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

OnTopic/Repositories/TopicRepository.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,14 +599,30 @@ public override sealed void Delete([ValidatedNotNull]Topic topic, bool isRecursi
599599
}
600600
}
601601

602+
/*------------------------------------------------------------------------------------------------------------------------
603+
| Remove references
604+
\-----------------------------------------------------------------------------------------------------------------------*/
605+
foreach (var descendantTopic in descendantTopics) {
606+
foreach (var reference in descendantTopic.References) {
607+
if (reference.Value is not null && !descendantTopics.Contains(reference.Value)) {
608+
descendantTopic.References.Remove(reference.Key);
609+
}
610+
}
611+
}
612+
602613
/*------------------------------------------------------------------------------------------------------------------------
603614
| Remove incoming relationships
604615
\-----------------------------------------------------------------------------------------------------------------------*/
605616
foreach (var descendantTopic in descendantTopics) {
606617
foreach (var relationship in descendantTopic.IncomingRelationships) {
607618
foreach (var relatedTopic in relationship.Values.ToList()) {
608619
if (!descendantTopics.Contains(relatedTopic)) {
609-
relatedTopic.Relationships.RemoveTopic(relationship.Key, descendantTopic);
620+
if (relatedTopic.Relationships.Contains(relationship.Key, descendantTopic)) {
621+
relatedTopic.Relationships.RemoveTopic(relationship.Key, descendantTopic);
622+
}
623+
else if (relatedTopic.References.Contains(relationship.Key)) {
624+
relatedTopic.References.Remove(relationship.Key);
625+
}
610626
}
611627
}
612628
}

0 commit comments

Comments
 (0)