Skip to content

Merge master v5.2.0 into openapi #1273

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

Merged
merged 74 commits into from
May 13, 2023
Merged

Conversation

bkoelman
Copy link
Member

@bkoelman bkoelman commented May 12, 2023

This PR merges the latest master branch (v5.2.0) into the openapi branch.

Commits to review (the rest originates from merge):

QUALITY CHECKLIST

bkoelman and others added 30 commits February 9, 2023 12:31
…as not applied when determining total resource count via inverse relationship
Simplify assertions (ShouldContainKey already checks for null)
Fixed: incorrect meta:total on secondary endpoint with filter
… of a string value. This effectively moves the type resolving/conversion logic from the EF query production phase to the filter parsing phase. By providing a richer QueryLayer model, it becomes easier to implement non-relational and non-EF Core-based repositories. And it enables to produce better errors earlier.

Note we still need to wrap nullable values (see WhereClauseBuilder.ResolveCommonType), due to https://bradwilson.typepad.com/blog/2008/07/creating-nullab.html.
|          Method |     Mean |     Error |    StdDev | Ratio |   Gen0 | Allocated | Alloc Ratio |
|---------------- |---------:|----------:|----------:|------:|-------:|----------:|------------:|
|    TrackChanges | 3.741 us | 0.0122 us | 0.0114 us |  1.00 | 0.0229 |   6.41 KB |        1.00 |
| NewTrackChanges | 1.359 us | 0.0070 us | 0.0066 us |  0.36 | 0.0095 |   2.62 KB |        0.41 |

using BenchmarkDotNet.Attributes;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Middleware;
using JsonApiDotNetCore.Resources;
using JsonApiDotNetCore.Resources.Annotations;
using Microsoft.Extensions.Logging.Abstractions;

namespace Benchmarks.ChangeTracking;

// ReSharper disable once ClassCanBeSealed.Global
[MarkdownExporter]
[MemoryDiagnoser]
public class ChangeTrackerBenchmarks
{
    private readonly JsonApiRequest _request;
    private readonly TargetedFields _targetedFields;

    public ChangeTrackerBenchmarks()
    {
        IJsonApiOptions options = new JsonApiOptions();
        IResourceGraph resourceGraph = new ResourceGraphBuilder(options, NullLoggerFactory.Instance).Add<ExampleResource, long>().Build();
        ResourceType resourceType = resourceGraph.GetResourceType<ExampleResource>();

        _request = new JsonApiRequest
        {
            PrimaryResourceType = resourceType,
            IsCollection = true
        };

        _targetedFields = new TargetedFields();

        foreach (AttrAttribute attribute in resourceType.Attributes)
        {
            _targetedFields.Attributes.Add(attribute);
        }
    }

    [Benchmark(Baseline = true)]
    public void TrackChanges()
    {
        var changeTracker = new ResourceChangeTracker<ExampleResource>(_request, _targetedFields);

        var resource = new ExampleResource
        {
            Id = 1,
            Attr1 = "some",
            Attr2 = "more",
            Attr3 = "other",
            Attr4 = false,
            Attr5 = 123,
            Attr6 = default,
            Attr7 = default,
            Attr8 = default,
            Attr9 = DayOfWeek.Sunday
        };

        changeTracker.SetInitiallyStoredAttributeValues(resource);

        resource = new ExampleResource
        {
            Id = 1,
            Attr1 = "new",
            Attr2 = "change",
            Attr3 = "this",
            Attr4 = true,
            Attr5 = 456,
            Attr6 = default,
            Attr7 = default,
            Attr8 = default,
            Attr9 = DayOfWeek.Saturday
        };

        changeTracker.SetFinallyStoredAttributeValues(resource);

        changeTracker.HasImplicitChanges();
    }

    [Benchmark]
    public void NewTrackChanges()
    {
        var changeTracker = new NewResourceChangeTracker<ExampleResource>(_request, _targetedFields);

        var resource = new ExampleResource
        {
            Id = 1,
            Attr1 = "some",
            Attr2 = "more",
            Attr3 = "other",
            Attr4 = false,
            Attr5 = 123,
            Attr6 = default,
            Attr7 = default,
            Attr8 = default,
            Attr9 = DayOfWeek.Sunday
        };

        changeTracker.SetInitiallyStoredAttributeValues(resource);

        resource = new ExampleResource
        {
            Id = 1,
            Attr1 = "new",
            Attr2 = "change",
            Attr3 = "this",
            Attr4 = true,
            Attr5 = 456,
            Attr6 = default,
            Attr7 = default,
            Attr8 = default,
            Attr9 = DayOfWeek.Saturday
        };

        changeTracker.SetFinallyStoredAttributeValues(resource);

        changeTracker.HasImplicitChanges();
    }

    private sealed class ExampleResource : Identifiable<long>
    {
        [Attr]
        public string? Attr1 { get; set; }

        [Attr]
        public string? Attr2 { get; set; }

        [Attr]
        public string? Attr3 { get; set; }

        [Attr]
        public bool Attr4 { get; set; }

        [Attr]
        public int Attr5 { get; set; }

        [Attr]
        public DateTime Attr6 { get; set; }

        [Attr]
        public DateTimeOffset Attr7 { get; set; }

        [Attr]
        public TimeSpan Attr8 { get; set; }

        [Attr]
        public DayOfWeek Attr9 { get; set; }
    }
}
Caused by an unintentional breaking change in .NET SDK v7.0.200, which the latest AppVeyor image uses
…n request path ended with a slash. For example: /workItems/ => /workItems//1
Before: Expected element.GetInt32() to be 25, but found 2 (difference of -23).
After: Expected responseDocument.Meta to be 25, but found 2 (difference of -23).
Fix namespace imports in controller source generator
bkoelman and others added 23 commits April 20, 2023 01:48
…, demonstrating how to implement a custom read-only resource service and resource repository, which compiles the produced LINQ query and executes it against the dataset.
…tic expression value; fix potential NullReferenceException; use culture-insensitive conversion when no string specified
Harden Attr/Relationship attributes against invalid input
1. Owned entity properties are not retrieved when using sparse fieldsets (because they are modeled as navigations in EF Core, instead of scalar properties)
2. When producing a LINQ query that includes an owned entity, EF Core produces an error, indicating that the query must be marked as non-tracked. Due to potential performance impact, a virtual method is provided that enables tweaking the behavior.
@codecov
Copy link

codecov bot commented May 12, 2023

Codecov Report

Merging #1273 (b42a071) into openapi (d82c754) will increase coverage by 0.26%.
The diff coverage is 94.85%.

❗ Current head b42a071 differs from pull request most recent head 47d1ee3. Consider uploading reports for the commit 47d1ee3 to get more accurate results

@@             Coverage Diff             @@
##           openapi    #1273      +/-   ##
===========================================
+ Coverage    92.34%   92.61%   +0.26%     
===========================================
  Files          304      316      +12     
  Lines         8875     9313     +438     
===========================================
+ Hits          8196     8625     +429     
- Misses         679      688       +9     
Impacted Files Coverage Δ
...tityFrameworkExample/Repositories/TagRepository.cs 0.00% <0.00%> (ø)
...Annotations/Resources/Annotations/AttrAttribute.cs 90.00% <ø> (ø)
...ons/Resources/Annotations/RelationshipAttribute.cs 88.88% <ø> (ø)
...sonApiDotNetCore/Diagnostics/CascadingCodeTimer.cs 0.00% <0.00%> (ø)
...Core/Repositories/EntityFrameworkCoreRepository.cs 96.05% <61.11%> (-1.56%) ⬇️
...c/JsonApiDotNetCore/Middleware/ExceptionHandler.cs 88.88% <75.00%> (-8.68%) ⬇️
...iDotNetCore/Middleware/JsonApiRoutingConvention.cs 92.75% <75.00%> (ø)
...EntityFrameworkExample/Services/TodoItemService.cs 77.77% <77.77%> (ø)
src/Examples/MultiDbContextExample/Program.cs 93.44% <80.95%> (-6.56%) ⬇️
...ore/AtomicOperations/OperationProcessorAccessor.cs 95.23% <88.88%> (+0.79%) ⬆️
... and 46 more

... and 1 file with indirect coverage changes

@bkoelman bkoelman marked this pull request as ready for review May 12, 2023 20:49
@bkoelman bkoelman requested a review from maurei May 12, 2023 20:49
@maurei maurei merged commit adff2a9 into openapi May 13, 2023
@maurei maurei deleted the merge-master-v5.2.0-into-openapi branch May 13, 2023 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants