Skip to content

Commit

Permalink
Resolves PR request
Browse files Browse the repository at this point in the history
  • Loading branch information
Kali-Sh committed May 14, 2024
1 parent ac625bf commit 391c950
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Elders.Cronus/EventStore/PagingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public PagingOptions(int take, byte[] paginationToken, Order order)

public static PagingOptions Empty() => new PagingOptions();

public string Serialize()
public override string ToString()
{
return Convert.ToBase64String(JsonSerializer.SerializeToUtf8Bytes(this));
}

public static PagingOptions Deserialize(string paginationToken)
public static PagingOptions From(string paginationToken)
{
PagingOptions pagingOptions = Empty();
if (string.IsNullOrEmpty(paginationToken) == false)
Expand Down
2 changes: 2 additions & 0 deletions src/Elders.Cronus/Projections/ProjectionQueryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace Elders.Cronus.Projections.Cassandra;

public ProjectionQueryOptions(IBlobId id, ProjectionVersion version, PagingOptions options) : this(id, version, options, null, options.Take) { }

public ProjectionQueryOptions(IBlobId id, ProjectionVersion version) : this(id, version, null, null, DefaultBatchSize) { }

public IBlobId Id { get; } = id;

public ProjectionVersion Version { get; } = version;
Expand Down
12 changes: 2 additions & 10 deletions src/Elders.Cronus/Projections/ProjectionStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,12 @@ public ProjectionStream(ProjectionVersion version, IBlobId projectionId, IEnumer
this.events = events;
}

public async Task<T> RestoreFromHistoryAsync<T>(T projection, Order order = null) where T : IProjectionDefinition
public async Task<T> RestoreFromHistoryAsync<T>(T projection) where T : IProjectionDefinition
{
if (events.Any() == false)
return default(T);

IEnumerable<IEvent> eventsOrderedByTimestamp;
if (order is null || order == Order.Ascending)
{
eventsOrderedByTimestamp = events.OrderBy(@event => @event.Timestamp);
}
else
{
eventsOrderedByTimestamp = events.OrderByDescending(@event => @event.Timestamp); // Use load by descening with discretion, it might go bum bam when initizlizing the state, if you dont know what you are doing.
}
IEnumerable<IEvent> eventsOrderedByTimestamp = events.OrderBy(@event => @event.Timestamp);

projection.InitializeState(projectionId, null);
foreach (IEvent @event in eventsOrderedByTimestamp)
Expand Down

0 comments on commit 391c950

Please sign in to comment.