• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lucaslorentz / auto-compute / 18743477386

23 Oct 2025 01:20AM UTC coverage: 83.516% (+0.2%) from 83.356%
18743477386

push

github

lucaslorentz
Optimise incremental context enrichment

4 of 4 new or added lines in 1 file covered. (100.0%)

3 existing lines in 2 files now uncovered.

1829 of 2190 relevant lines covered (83.52%)

864.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.48
/src/LLL.AutoCompute/EntityContexts/NavigationEntityContext.cs
1
using System.Linq.Expressions;
2

3
namespace LLL.AutoCompute.EntityContexts;
4

5
public class NavigationEntityContext : EntityContext
6
{
7
    private readonly EntityContext _parent;
8
    private readonly IObservedNavigation _navigation;
9
    private bool _shouldLoadAll;
10

11
    public NavigationEntityContext(
12
        Expression expression,
13
        EntityContext parent,
14
        IObservedNavigation navigation)
15
        : base(expression, [parent])
190✔
16
    {
17
        _parent = parent;
190✔
18
        _navigation = navigation;
190✔
19
        IsTrackingChanges = parent.IsTrackingChanges;
190✔
20
    }
21

22
    public override IObservedEntityType EntityType => _navigation.TargetEntityType;
1,158✔
UNCOV
23
    public IObservedNavigation Navigation => _navigation;
×
24
    public override bool IsTrackingChanges { get; }
176✔
25

26
    public override async Task<IReadOnlyCollection<object>> GetParentAffectedEntities(object input, IncrementalContext incrementalContext)
27
    {
28
        // Short circuit to avoid requiring inverse navigation when no tracked property is accessed
29
        if (!GetAllObservedMembers().Any())
1,544✔
30
            return [];
356✔
31

32
        var inverseNavigation = _navigation.GetInverse();
1,188✔
33

34
        var sourceType = _navigation.SourceEntityType;
1,188✔
35

36
        var entities = await GetAffectedEntitiesAsync(input, incrementalContext);
1,188✔
37

38
        var parentEntities = new HashSet<object>();
1,188✔
39
        foreach (var (ent, parents) in await inverseNavigation.LoadOriginalAsync(input, entities))
2,520✔
40
        {
41
            foreach (var parent in parents)
284✔
42
            {
43
                if (!sourceType.IsInstanceOfType(parent))
70✔
44
                    continue;
45

46
                parentEntities.Add(parent);
70✔
47
                incrementalContext?.AddOriginalEntity(parent, _navigation, ent);
70✔
48
            }
49
        }
50
        foreach (var (ent, parents) in await inverseNavigation.LoadCurrentAsync(input, entities))
4,328✔
51
        {
52
            foreach (var parent in parents)
3,868✔
53
            {
54
                if (!sourceType.IsInstanceOfType(parent))
958✔
55
                    continue;
56

57
                parentEntities.Add(parent);
958✔
58
                incrementalContext?.AddCurrentEntity(parent, _navigation, ent);
958✔
59
            }
60
        }
61
        return parentEntities;
1,188✔
62
    }
63

64
    public override async Task EnrichIncrementalContextFromParentAsync(object input, IReadOnlyCollection<object> parentEntities, IncrementalContext incrementalContext)
65
    {
66
        var entities = new HashSet<object>();
260✔
67

68
        var parentEntitiesByLoadAll = parentEntities
260✔
69
            .ToLookup(e => _shouldLoadAll || incrementalContext.ShouldLoadAll(e));
514✔
70

71
        var parentEntitiesToLoadAll = parentEntitiesByLoadAll[true].ToArray();
260✔
72

73
        foreach (var (parent, ents) in await _navigation.LoadOriginalAsync(input, parentEntitiesToLoadAll))
552✔
74
        {
75
            foreach (var ent in ents)
60✔
76
            {
77
                entities.Add(ent);
14✔
78
                incrementalContext.AddOriginalEntity(parent, _navigation, ent);
14✔
79
                if (incrementalContext.ShouldLoadAll(parent))
14✔
80
                    incrementalContext.SetShouldLoadAll(ent);
12✔
81
            }
82
        }
83

84
        foreach (var (parent, ents) in await _navigation.LoadCurrentAsync(input, parentEntitiesToLoadAll))
556✔
85
        {
86
            foreach (var ent in ents)
64✔
87
            {
88
                entities.Add(ent);
14✔
89
                incrementalContext.AddCurrentEntity(parent, _navigation, ent);
14✔
90
                if (incrementalContext.ShouldLoadAll(parent))
14✔
91
                    incrementalContext.SetShouldLoadAll(ent);
10✔
92
            }
93
        }
94

95
        foreach (var parentEntity in parentEntitiesByLoadAll[false])
992✔
96
        {
97
            foreach (var entity in incrementalContext.GetEntities(parentEntity, _navigation))
950✔
98
            {
99
                entities.Add(entity);
239✔
100
            }
101
        }
102

103
        await EnrichIncrementalContextAsync(input, entities, incrementalContext);
260✔
104
    }
105

106
    public override async Task EnrichIncrementalContextTowardsRootAsync(object input, IReadOnlyCollection<object> entities, IncrementalContext incrementalContext)
107
    {
108
        var inverse = _navigation.GetInverse();
72✔
109

110
        var parentEntities = new HashSet<object>();
72✔
111

112
        foreach (var (ent, parents) in await inverse.LoadOriginalAsync(input, entities))
256✔
113
        {
114
            foreach (var parent in parents)
214✔
115
            {
116
                parentEntities.Add(parent);
51✔
117
                incrementalContext.AddOriginalEntity(parent, _navigation, ent);
51✔
118
            }
119
        }
120

121
        foreach (var (ent, parents) in await inverse.LoadCurrentAsync(input, entities))
260✔
122
        {
123
            foreach (var parent in parents)
188✔
124
            {
125
                parentEntities.Add(parent);
36✔
126
                incrementalContext.AddCurrentEntity(parent, _navigation, ent);
36✔
127
            }
128
        }
129

130
        await _parent.EnrichIncrementalContextTowardsRootAsync(input, parentEntities, incrementalContext);
72✔
131
    }
132

133
    public override async Task PreLoadNavigationsFromParentAsync(object input, IReadOnlyCollection<object> parentEntities)
134
    {
135
        var entities = new HashSet<object>();
1,284✔
136

137
        foreach (var (parent, ents) in await _navigation.LoadOriginalAsync(input, parentEntities))
3,000✔
138
        {
139
            foreach (var ent in ents)
832✔
140
                entities.Add(ent);
200✔
141
        }
142

143
        foreach (var (parent, ents) in await _navigation.LoadCurrentAsync(input, parentEntities))
4,868✔
144
        {
145
            foreach (var ent in ents)
4,652✔
146
                entities.Add(ent);
1,176✔
147
        }
148

149
        await PreLoadNavigationsAsync(input, entities);
1,284✔
150
    }
151

152
    public override void MarkNavigationToLoadAll()
153
    {
154
        _shouldLoadAll = true;
14✔
155
    }
156

157
    public override void ValidateSelf()
158
    {
159
        if (GetAllObservedMembers().Any())
190✔
160
        {
161
            _navigation.GetInverse();
142✔
162
        }
163
    }
164
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc