Commit a0b659d
committed
Don't save phantom attributes
In the previous commit, we patched an issue where empty attributes were being committed to the _extended attributes_ storage (c035ca0). But, in many cases, those attributes shouldn't exist in the first place.
There's no such thing as an empty attribtute in OnTopic; they should be treated as deletions. For this reason, the main reason we store `AttributeValue`s with a `null` or empty value is to signal to `ITopicRepository` implementations that there is a deletion that needs to be accounted for. But if the attribute never previously existed, then there's no attribute to delete, and the attribute should be ignored entirely.
This update prevents `null` or empty `AttributeValue`s from being added to the `AttributeValueCollection` via the `SetValue()` entry point. This doesn't solve any bugs, as these cases are handled downstream by the `ITopicRepository` and, potentially, their backend data stores. But it does help prevent unnecessary and extraneous objects from being added to the object graph, and thus might have present minor gains in terms of memory usage and performance.
It's worth noting that developers can still inect `null` or empty `AttributeValue`s directly by using e.g. the `Add()` entry point. We usually expect developers to access attributes via `SetValue()`, though, as it's eaiser than constructing a new `AttributeValue` and comparing it to existing values. If a developer is accessing the collection directly, we're assuming s/he knows what they're doing and will either prevent these values on their end, or has a good reason for adding them. Regardless, it's not the priority or concern of this patch.
Includes unit tests for validating functionality.1 parent c035ca0 commit a0b659d
2 files changed
Lines changed: 49 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
306 | 345 | | |
307 | 346 | | |
308 | 347 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
310 | 320 | | |
311 | 321 | | |
312 | 322 | | |
| |||
0 commit comments