Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Allow stream message json data to not be prefetched during stream reading. - #49

Merged
damianh merged 13 commits into
masterfrom
async-json-data
Nov 8, 2016
Merged

damianh merged 13 commits into
masterfrom
async-json-data

Conversation

@damianh

@damianh damianh commented Nov 7, 2016

Copy link
Copy Markdown
Member

When reading a stream (or all) you may not be interested in the JsonData payload of every single message. As there is currently no limit on the size of the JsonData payload in the core (limitation is store specific), this PR allows the user to disable prefetching of that JsonData

The key changes are:

  • IReadOnlyStreamStore.ReadAllForwards(), .ReadAllBackwards(), .ReadStreamForwards(), .ReadStreamBackwards() all have an additional, optional parameter prefetchJsonData = true.
  • StreamMessage.JsonData {get;} property has been replaced with a method Task<string> StreamMessage.GetJsonData(). When prefetch is turned off this will result will result in a call to the server.
  • InMemoryStreamStore simulates the async nature using a task offload if prefetching is turned off.
  • Prefetching is enabled by default.

Note there is a condition where the message may be deleted between handling a StreamMessage instance and calling the GetJsonData(). The implementation here is to return a null when that occurs.

This is a breaking change.

@damianh damianh added this to the v0.5.0 milestone Nov 7, 2016
@damianh damianh self-assigned this Nov 7, 2016
@damianh

damianh commented Nov 7, 2016

Copy link
Copy Markdown
Member Author

Note: I'd like to separately support reads that allow server side of filtering by StreamMessage.Type or StreamId prefix.


message.MessageId.ShouldBe(expectedMessage.MessageId);
message.JsonData.ShouldBe(expectedMessage.JsonData);
(await message.GetJsonData()).ShouldBe(await expectedMessage.GetJsonData());

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main breaking change for consumers.

Task<ReadAllPage> ReadAllForwards(
long fromPositionInclusive,
int maxCount,
bool prefetchData = true,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The additional optional parameter.

private readonly Func<int> _getNextPosition;
private readonly List<InMemoryStreamMessage> _events = new List<InMemoryStreamMessage>();
private readonly Dictionary<Guid, InMemoryStreamMessage> _eventsById = new Dictionary<Guid, InMemoryStreamMessage>();
private readonly List<InMemoryStreamMessage> _messages = new List<InMemoryStreamMessage>();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took the opportunity to clean up when I saw it.

@damianh

damianh commented Nov 7, 2016

Copy link
Copy Markdown
Member Author

I should add, one of the other drivers of this was the HTTP API where we want to be able to GET streams with links to individual message json data (as opposed to embedding it).

@damianh
damianh merged commit 1374599 into master Nov 8, 2016
@damianh
damianh deleted the async-json-data branch November 8, 2016 08:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant