Skip to content

Commit 66ccd9d

Browse files
committed
Merge branch 'feature/Relationships-abstraction' into develop
Previously, the `Topic.Relationships` implementation exposed a lot of members that weren't needed by most callers—and, in doing so, introduced the opportunity for backdoors that would inadvertently bypass state tracking and reciprocal relationship handling. This is resolved by the introduction of the new `TopicRelationshipMultiMap` class (57ff3f9, 7129289) to replace the legacy `RelatedTopicCollection`. This offers a cleaner interface, and eliminates the risk of introducing bugs by writing to the internal collections directly, as the underlying data store is now hidden behind a façade. In addition, the underlying collections now allow relationships to different topics with the same `Topic.Key`—an unlikely scenario, but one which would previously cause problems. Breaking Changes - The `RelatedTopicCollection` and `NamedTopicCollection` previously used by `Topic.Relationships` have been replaced by `TopicRelationshipMultiMap` (57ff3f9, 7129289), `ReadOnlyTopicMultiMap` (eb5c1c3), and `TopicMultiMap` (d049ea9). - Care was provided to maintain the overall interface, but calls to the underlying collections will have changed. Most notably, all write operations _must_ now go through `SetTopic()`, `RemoveTopic()`, or `ClearTopics()`. - In addition, for callers iterating over the relationships, the relationship key is now `Key` not `Name`, the topics are now stored under a `Values` property, and the friendly interfaces require a fully-qualified `Topic`, instead of a `Topic.Key` (0d9dcd5).
2 parents ce3cc43 + db53dd5 commit 66ccd9d

17 files changed

+1014
-913
lines changed

OnTopic.AspNetCore.Mvc/Controllers/SitemapController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ where topic.Attributes.GetValue(attribute.Key)?.Length < 256
236236
IEnumerable<XElement> getRelationships() =>
237237
from relationship in topic.Relationships
238238
select new XElement(_pagemapNamespace + "DataObject",
239-
new XAttribute("type", relationship.Name),
240-
from relatedTopic in topic.Relationships[relationship.Name]
239+
new XAttribute("type", relationship.Key),
240+
from relatedTopic in relationship.Values
241241
select new XElement(_pagemapNamespace + "Attribute",
242242
new XAttribute("name", "TopicKey"),
243243
new XText(relatedTopic.GetUniqueKey().Replace("Root:", "", StringComparison.InvariantCultureIgnoreCase))

OnTopic.Data.Sql/SqlTopicRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ SqlDateTime version
418418
\-----------------------------------------------------------------------------------------------------------------------*/
419419
if (
420420
isRecursive &&
421-
( topic.Relationships.Any(r => r.Any(t => t.Id < 0)) ||
421+
( topic.Relationships.Any(r => r.Values.Any(t => t.Id < 0)) ||
422422
topic.References.Values.Any(t => t.Id < 0)
423423
)
424424
) {
@@ -654,7 +654,7 @@ private static void PersistRelations(Topic topic, SqlConnection connection) {
654654

655655
//Reset isDirty, assuming there aren't any unresolved references
656656
if (savedTopics.Count() == relatedTopics.Count) {
657-
relatedTopics.MarkClean();
657+
topic.Relationships.MarkClean(key);
658658
}
659659

660660
}

OnTopic.Tests/NamedTopicCollection.cs

Lines changed: 0 additions & 197 deletions
This file was deleted.

0 commit comments

Comments
 (0)