Skip to content

Commit 006efc0

Browse files
committed
Adds some comments
1 parent 1a5ca79 commit 006efc0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Elders.Cronus/Projections/Rebuilding/RebuildProjectionSequentially_Job.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,21 @@ protected override async Task<JobExecutionStatus> RunJobAsync(IClusterOperations
9898
{
9999
OnAggregateStreamLoadedAsync = async stream =>
100100
{
101+
// 1. It is important to check all EventHandlers if they are interested in specific events and do this FIRST.
101102
List<AggregateEventRaw> rawEvents = [];
102103
foreach (string eventTypeContract in projectionEventsContractIds)
103104
{
104-
var interested = stream.Commits
105+
IEnumerable<AggregateEventRaw> interested = stream.Commits
105106
.SelectMany(x => x.Events)
106107
.Where(x => IsInterested(eventTypeContract, x.Data));
107108

109+
// Do not try to optimize the GC using Enumerable.Concat because it does not solve the issue
108110
rawEvents.AddRange(interested);
109111
}
110112

111-
foreach (var eventRaw in rawEvents.OrderBy(x => x.Revision).ThenBy(x => x.Position))
113+
// 2. Then the result is sorted!
114+
IEnumerable<AggregateEventRaw> rawEventsSorted = rawEvents.OrderBy(x => x.Revision).ThenBy(x => x.Position); // Do not try to optimize the sorting with SortedDictionary. It is not faster.
115+
foreach (AggregateEventRaw eventRaw in rawEventsSorted)
112116
{
113117
var @event = serializer.DeserializeFromBytes<IEvent>(eventRaw.Data).Unwrap();
114118
if (@event is null)

0 commit comments

Comments
 (0)