Commit afa1e9b
committed
Merge branch 'feature/track-dirty-relationships' into develop
Introduced support to track whether (any) relationships are "dirty"—i.e., whether or not they've been saved since they were last loaded from the database. Unlike attributes, which have a special `AttributeValue` container that can be decorated with an `IsDirty` property, relationships are just direct pointers to the target `Topic`. Instead, `IsDirty` is placed on the `NamedTopicCollection` which acts as the container for _all_ of the relationships (4762694). In addition, the `RelatedTopicCollection`—which tracks multiple relationships associated with a topic—has an `IsDirty()` method which rolls up this functionality (2adef58). Finally, an `isDirty` parameter was added to `RelatedTopicCollection.SetTopic()` to prevent the setting of a relationship from tripping the `IsDirty` status (2f1e2bf), which enables us to disable that functionality on `SqlTopicRepository.Load()` (7081c39) and reset it on `SqlTopicRepository.Save()` (8147562).
This introduces a number of other capabilities which have the potential to greatly reduce unnecessary database access and, therefore, performance during a recursive `Save()` of a large topic graph. Previously, _all_ topics would be saved, regardless of whether any content had changed. This is because we didn't know which relationships, if any, had changed, so we would delete them all (via `UpdateTopic`'s `@DeleteRelationships` parameter), then recreate them via the `PersistRelations` stored procedure. With `RelatedTopicCollection.IsDirty()` in place, we can now conditionally ignore those if no relationships have changed (1fc3a6f)—and, better, ignore the entire `Save()` if `AttributeValueCollection.IsDirty()` is _also_ false (1fc3a6f). In fact, we can even bypass much of the logic in `Save()`, except for that necessary to determine the state (3fd9720). This resolves "Track whether relationships have changed" (#23).
In addition, this also factors in the bug fix to a closely related bug, "Handle attribute configuration mismatch on `Save()`" (#24), in which attributes whose configuration `AttributeDescriptor.IsExtendedAttribute` had changed, but whose _value_ (and, therefore, `IsDirty` flag) had not changed could potentially be orphaned. This was resolved in a previous bug fix (d64d242), but needs to be accounted for here to ensure that topics are still `Save()` even if `AttributeValueCollection.IsDirty()` and `RelatedTopicCollection.IsDirty()` are both `false` if there are any _attribute configuration mismatches`, as detected by `TopicRepositoryBase.IsExtendedAttributeMismatch()` (a3d4798).
Finally, while I was at it, I made a handful of other optimizations and refactorings to the `SqlTopicRepository` code base:
- Implemented C# 8's new inline `using` syntax instead of explicitly calling `Dispose()` in a `finally` block (f85aab2)
- Introduced `AttributeValuesDataTable` (313fe71) and `TopicLIstDataTable` (7a37dc9) to model the user-defined table-valued types in SQL.
- Extended `SqlCommant.AddParameter()` to support `DataTable` objects, and derivatives (0cd2506).
- Removed unused legacy support for `CreateRelationshipsXml()` and `skipXml` (7bea7d3)
- Introduced `Topic.IsSaved` property for determining if a topic has been saved (1678523)File tree
14 files changed
+568
-240
lines changed- OnTopic.Data.Caching
- OnTopic.Data.Sql
- Models
- OnTopic.TestDoubles
- OnTopic.Tests
- OnTopic
- Collections
- Mapping
- Repositories
14 files changed
+568
-240
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | 145 | | |
151 | 146 | | |
152 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
84 | 93 | | |
85 | 94 | | |
86 | 95 | | |
| |||
145 | 154 | | |
146 | 155 | | |
147 | 156 | | |
| 157 | + | |
148 | 158 | | |
149 | 159 | | |
150 | 160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
321 | | - | |
| 321 | + | |
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
| |||
0 commit comments