You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge branch 'feature/TopicRepositoryBase-Improvements' into develop
Improved handling of the GetContentTypes() cache in `TopicRepositoryBase`
In a previous update, I made significant updates to how the `GetContentTypeDescriptors()` are cached, in order to help ensure the current configuration is always being assessed when editing or saving topics via e.g. the OnTopic Editor (fb3366e). Unfortunately, while these updates were sufficient for handling most `Import()` scenarios needed for bootstrapping a new database (695664d), they were not enough to allow for live reconfiguration in most real-world scenarios. That is, after a change is made to the Oroborus Configuration (e.g., via `Root:Configuration:ContentTypes`), the application must be restarted before that change will take effect; it doesn't happen immediately.
This was largely due to the fact that the `CachedTopicRepository`, which most sites use for performance reasons, operates off of a decorator pattern. This makes it easy for it to operate cache _any_ `ITopicRepository` instance, not just e.g. `SqlTopicRepository`. But, in doing so, it also makes it difficult for it to interact with and share caching data with the underlying `TopicRepositoryBase` used by e.g. `SqlTopicRepository`. That's notable since `TopicRepositoryBase` maintains its own cache of `ContentTypes`. As such, when those are updated via e.g. the OnTopic Editor, they are updated in the `CacheTopicRepository` topic graph, but not necessarily the `SqlTopicRepository`'s underlying `TopicRepositoryBase._contentTypeDescriptors` cache.
As such, while the previous updates (fb3366e) added features for importing missing `AttributeDescriptor`s and `ContentTypeDescriptor`s from the topic graph, and even resetting aspects of the local cache, such as the `ContentTypeDescriptor.AttributeDescriptors` collection, when updating a `ContentTypeDescriptor` or `AttributeDescriptor`, this didn't do much good if the versions of the objects in the `TopicRepositoryBase._contentTypeDescriptors` cache were not necessarily the same as those in the `CachedtopicRepository` cache. In those cases, having e.g. the inheritance structure of `AttributeDescriptors` refreshed wouldn't necessarily pick up new results.
To mitigate this, significant changes have been made to help ensure that the objects being cached in the `TopicRepositoryBase` and, thus, `SqlTopicRepository` are, in fact, the same ones being referenced by `CachedTopicRepository`. To support this, the following changes were made:
- Introduced a new `ContentTypeDescriptorCollection.Refresh()` method (3e3930f) and corresponding constructor overload (60d4d8b) which allows the cache to be updated based on a root `ContentTypeDescriptor` (b206f3e)
- Configured `GetContentTypeDescriptors()` (946ddb9) and `GetContentTypeDescriptors(ContentTypeDescriptor)` (afbfa47), and even `Delete()` (afe7b70) to use the new `Refresh()` method, thus simplifying and centralizing their logic
- Renamed `GetContentTypeDescriptors(ContentTypeDescriptor)` to `SetContentTypeDescriptors()` (f1ade10, 78a9d3f, c75bbe2) so it's clearer that this will update the cache based on the parameter
- Fixed a bug in `TopicRepositoryBase.Move()` which prevented `ResetAttributeDescriptors()` from being called when a topic was moved (5941385, d7a61cd, b2f27e8, 23f4cb1); this additionally depends on a bug fix in `OnTopic.Editor.AspNetCore`
- Initialize the `SetContentTypeDescriptors()` cache on the initial call to `TopicRepositoryBase.Load()`; in most scenarios, this will be the warming of the `CachedTopicRepository` cache, thus ensuring the cache is shared between both e.g. `SqlTopicRepository` and `CachedTopicRepository` (dcdbab2)
- Introduced a new `ContentTypeDescriptor.ResetPermittedContentTypes()` method (9a7ef01) so that the cached collection of permitted `ContentTypeDescriptor`s is updated whenever a `ContentTypeDescriptor`'s `Relationships` are updated
In addition, while I was at it, I performed a number of other cleanup tasks mostly related to the `TopicRepositoryBase` class:
- Updated the XML Docs to reflect previous extensions to `AttributeValueCollection.SetValue()` (8aea8e7, 10c7c09) and `RelatedTopicCollection.SetTopic()` (27391f5, 2f1e2bf)
- Removed redundant update to cache in `SqlTopicRepository.Save()` (df7e6d2)
- Expanded explanation for `ResetAttributeDescriptors()` method (3f952a6)
- Implemented preferred pattern-matching syntax (d175f22)
- Removed unnecessary `[NotNull]` attribute on base classes to avoid confusion with Roslyn's static flow analysis (2210b29)
- Fixed unit test issues which covered up previous bugs (f980ef8, 6c081d8)
0 commit comments