-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
MudDataGrid: Make AggregateDefinition work with nullable values and cover with tests #6515
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## dev #6515 +/- ##
==========================================
+ Coverage 91.17% 91.46% +0.29%
==========================================
Files 392 393 +1
Lines 14826 14874 +48
==========================================
+ Hits 13517 13605 +88
+ Misses 1309 1269 -40
... and 5 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
I will take a look. Thanks, @ScarletKuro ! |
@ScarletKuro, the ChangeExpressionReturnType is used to safely change the return type of an expression. It is just a helper so that you do not have to have that code repeated for each aggregate type expression. |
This I understand. I was more curious why for |
Hmm, I can't remember now, but it might have been because the MinMax aggregate is shared between min and max. |
I updated the HashCode, now it's more clean. I also added tests to I guess it really depends on use case. I'm not sure how AggregateDefinition is used in real world. The last word is yours. |
I don't think 500ns per call is anything to worry about here. The only time it would even possibly be an issue is when there are way too many groups expanded. Looks like the benefits outweigh the negligible perf hit. |
…over with tests (MudBlazor#6515) * Make AggregateDefinition work with nullable values and cover with tests
Description
This PR allows to have nullable types in
AggregateDefinition
. Original LINQ methods are able to work withint?
,long?
,decimal?
etc when calculatingMin
,Max
,Average
,Sum
. Previous implementation would throw exception.For this I changed
ChangeExpressionReturnType<T, decimal>
toChangeExpressionReturnType<T, decimal?>
.I'm also kinda curious why
ChangeExpressionReturnType<T, object>
was used, is there any reason behind it?I redid the cache. It's calculating the hash of the expression and stores it basically in a dictionary.
Previous one had a drawback, if you change the expression, but do not change the
AggregateType
, then it would evaluate the previous expression for this type, now you can reuse the same instance ofAggregateDefinition
without a problem.I know I had a really brief talk with adameste where I proposed the idea of expression cache class, and he had valid points against it. But I still decided to give it a try, because: we can make it not centralized, about the performance (slow read) -
AggregateDefinition
is not a hot spot class, as well we can dropConcurrentDictionary
and use something likeDictionarySlim
that has a single lookup forGetOrAdd
and performs better for value type keys. I didn't go for it because it's much more code and if only one class is going to use it then it's an overkill.Ofc this is all negotiable whatever we need this or not.
I made many unit tests to make sure everything works correctly, they should be readable and pretty straightforward. All existing unit tests that covered this before are also working.
I made a dedicated folder "DataGrid" in test project, since the DataGrid test file is already big, and since the component is really huge and important I would encourage in future to split it and test it class by class instead.
How Has This Been Tested?
New unit tests + existing unit tests
Types of changes
Checklist:
dev
).