reorder methods by importance
MODIFY
WalletWasabi/EventSourcing/InMemoryEventRepository.cs
WalletWasabi/EventSourcing/InMemoryEventRepository.cs
@@ -19,14 +19,6 @@ namespace WalletWasabi.EventSourcing
protected static readonly IReadOnlyList<WrappedEvent> EmptyResult = Array.Empty<WrappedEvent>().ToList().AsReadOnly();
protected static readonly IReadOnlyList<string> EmptyIds = Array.Empty<string>().ToList().AsReadOnly();
- private readonly ConcurrentDictionary<
- string /*aggregateType*/,
- (long LastIndex,
- ConcurrentDictionary<
- long, /*index*/
- string /*id*/> Ids)>
- _aggregatesIds = new();
-
private readonly ConcurrentDictionary<
string /*aggregateType*/,
ConcurrentDictionary<string /*id*/,
@@ -35,6 +27,14 @@ namespace WalletWasabi.EventSourcing
ConcurrentQueue<IReadOnlyList<WrappedEvent>> EventsBatches) /* sequence of atomically appended event batches */>>
_aggregatesEventsBatches = new();
+ private readonly ConcurrentDictionary<
+ string /*aggregateType*/,
+ (long LastIndex,
+ ConcurrentDictionary<
+ long, /*index*/
+ string /*id*/> Ids)>
+ _aggregatesIds = new();
+
public Task AppendEventsAsync(
string aggregateType,
string id,
@@ -98,6 +98,25 @@ namespace WalletWasabi.EventSourcing
return Task.CompletedTask;
}
+ public Task<IReadOnlyList<WrappedEvent>> ListEventsAsync(string aggregateType, string id, long fromSequenceId = 0, int? limit = null)
+ {
+ if (_aggregatesEventsBatches.TryGetValue(aggregateType, out var aggregateEventsBatches) &&
+ aggregateEventsBatches.TryGetValue(id, out var value))
+ {
+ var result = value.EventsBatches.SelectMany(a => a);
+ if (0 < fromSequenceId)
+ {
+ result = result.Where(a => fromSequenceId <= a.SequenceId);
+ }
+ if (limit.HasValue)
+ {
+ result = result.Take(limit.Value);
+ }
+ return Task.FromResult((IReadOnlyList<WrappedEvent>)result.ToList().AsReadOnly());
+ }
+ return Task.FromResult(EmptyResult);
+ }
+
public Task<IReadOnlyList<string>> ListAggregateIdsAsync(string aggregateType, string? fromId = null, int? limit = null)
{
if (fromId != null)
@@ -128,25 +147,6 @@ namespace WalletWasabi.EventSourcing
return Task.FromResult(EmptyIds);
}
- public Task<IReadOnlyList<WrappedEvent>> ListEventsAsync(string aggregateType, string id, long fromSequenceId = 0, int? limit = null)
- {
- if (_aggregatesEventsBatches.TryGetValue(aggregateType, out var aggregateEventsBatches) &&
- aggregateEventsBatches.TryGetValue(id, out var value))
- {
- var result = value.EventsBatches.SelectMany(a => a);
- if (0 < fromSequenceId)
- {
- result = result.Where(a => fromSequenceId <= a.SequenceId);
- }
- if (limit.HasValue)
- {
- result = result.Take(limit.Value);
- }
- return Task.FromResult((IReadOnlyList<WrappedEvent>)result.ToList().AsReadOnly());
- }
- return Task.FromResult(EmptyResult);
- }
-
private void IndexNewAggregateId(string aggregateType, string id)
{
var lastIndex = 0L;

reorder methods by importance