-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix driver results initialization method usage with dynamic caching #16644
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some formatting feedback.
If with this fix, we no longer calls the initializer of a model when the shape is cached, I am wondering if you would notice a performance improvement?
From the looks of it, we should see reduction in allocations.
src/OrchardCore/OrchardCore.DisplayManagement/Handlers/BuildDisplayContext.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.DisplayManagement/Handlers/BuildShapeContext.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.DisplayManagement/Handlers/DisplayDriverBase.cs
Show resolved
Hide resolved
return shape; | ||
}); | ||
initialize?.Invoke(shape); | ||
return Task.FromResult(shape); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return Task.FromResult(shape); | |
return Task.FromResult(shape); |
initialize((TModel)shape); | ||
return new ValueTask<IShape>(shape); | ||
initialize?.Invoke(model); | ||
return ValueTask.CompletedTask; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return ValueTask.CompletedTask; | |
return ValueTask.CompletedTask; |
var contentShape = await factory.CreateAsync("Content"); | ||
await shapeResult.ApplyAsync(new BuildDisplayContext(contentShape, "Detail", "", factory, null, null)); | ||
|
||
// Shape is created and initialized |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Shape is created and initialized | |
// Shape is created and initialized. |
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var buildDisplayContext = new BuildDisplayContext(contentShape, "Detail", "", factory, null, null); | ||
var driverResult = new MyDisplayDriver().Display(contentItem, buildDisplayContext); | ||
await driverResult.ApplyAsync(buildDisplayContext); | ||
return driverResult; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return driverResult; | |
return driverResult; |
public int MyProperty { get; set; } = 3; | ||
} | ||
|
||
public class MyDisplayDriver : ContentDisplayDriver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public class MyDisplayDriver : ContentDisplayDriver | |
public sealed class MyDisplayDriver : ContentDisplayDriver |
{ | ||
public override IDisplayResult Display(ContentItem model, BuildDisplayContext context) | ||
{ | ||
return Initialize<MyModel>(model => model.MyProperty++).Location("Content").Cache("id", ctx => ctx.WithExpiryAfter(TimeSpan.FromSeconds(1))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return Initialize<MyModel>(model => model.MyProperty++).Location("Content").Cache("id", ctx => ctx.WithExpiryAfter(TimeSpan.FromSeconds(1))); | |
return Initialize<MyModel>(model => model.MyProperty++) | |
.Location("Content") | |
.Cache("id", ctx => ctx.WithExpiryAfter(TimeSpan.FromSeconds(1))); |
…splayContext.cs Co-authored-by: Mike Alhayek <[email protected]>
…apeContext.cs Co-authored-by: Mike Alhayek <[email protected]>
Mike was reporting that when cache the delegate passed in the
Initialize
method of a driver was invoked every time. At some point this has been broken and the delegate was used directly instead of being provided as theShapeMetadata.OnProcessing
value.This fixes it and adds unit tests. There is no breaking change, just a few refactorings to make the methods dependencies more logical.