Lazily create content and models in NuCache #6346
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is primarily to resolve issues when schema type changes are made (i.e. content types and data types) which until this PR would result in PureLive models being rebuild dozens of times and since package install/uninstall performs many of these changes and restarts, these operations would cause all sorts of odd problems due to the amount of PureLive models being rebuilt.
With this change, the creation of the models (calls to
CreateModel
) are done lazily so only when the content is actually request. In theory this means that in the ContentTypeCacheRefresher and DataTypeCacheRefresher we wouldn't need to explicitly callWithSafeLiveFactory
to re-compile the models eagerly, instead we would just leave the re-compilation to execute lazily when the models are needed.Some investigation is needed with this PR to ensure that it works as anticipated. One thing we'll need to think about is that even though we then shouldn't call
WithSafeLiveFactory
eagerly when schema types change, this call used to call theRefresh
method of the PureLiveFactory (see https://github.com/zpqrtbnk/Zbu.ModelsBuilder/blob/v8/dev/src/Umbraco.ModelsBuilder/Umbraco/PureLiveModelFactory.cs#L81) which would do both ResetModels + EnsureModels, whereas if we don't call this and only rely on theCreateModel
call to ensure models, it only ends up callingEnsureModels
and not alsoResetModels
... need to figure out if that is a required call or not.