Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging API: get size of a stream to read #503

Merged
merged 10 commits into from
Nov 29, 2018

Conversation

mpraglowski
Copy link
Member

When you have read specification like:

scope = res.read.stream('Dummy').backward.from(:head).limit(10)

you could get a size of result set by using new API method: scope.count before you read all data from the stream by scope.each { .... } or scope.to_a.

@mostlyobvious
Copy link
Member

count seems to be the method on Enumerable as well so good choice: https://ruby-doc.org/core-2.5.0/Enumerable.html#method-i-count

@mpraglowski mpraglowski force-pushed the size-of-a-stream-to-read branch from 7f45229 to cf573c5 Compare November 28, 2018 13:05
private

def read_scope(spec)
raise RubyEventStore::ReservedInternalName if spec.stream.name.eql?(EventRepository::SERIALIZED_GLOBAL_STREAM_NAME)
Copy link
Member

Choose a reason for hiding this comment

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

not a part of read_scope, please move it back to read

@@ -81,6 +81,12 @@ def read(specification)
@events.read(specification)
end

def count(specification)
raise ReservedInternalName if specification.stream.name.eql?(@stream_entries.stream_entries.class::SERIALIZED_GLOBAL_STREAM_NAME)
Copy link
Member

Choose a reason for hiding this comment

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

not a part of count

Copy link
Member Author

Choose a reason for hiding this comment

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

should count allow for reserved name used in stream specification? maybe this check should be in Specification class (via SpecificationReader where we know repository)

Copy link
Member

Choose a reason for hiding this comment

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

oh, if count omits read than it can check for reserved name (reminder that name will no longer be reserved after #312 materializes)

Copy link
Member Author

Choose a reason for hiding this comment

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

So we should remove that check in #312 or after.


if specification.batched?
reader = ->(offset, limit) do
query_builder(query, offset: offset, limit: limit).to_ary
end
BatchEnumerator.new(specification.batch_size, limit || Float::INFINITY, reader).each
BatchEnumerator.new(specification.batch_size, specification.limit, reader).each
Copy link
Member

Choose a reason for hiding this comment

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

Missed change from a different commit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope - just simplification.

Was:

limit = specification.limit if specification.limit?
and later as argument: limit || Float::INFINITY

but that's not needed because specification.limit is Float::INFINITY if limit has not been specified.

@mostlyobvious
Copy link
Member

Please rebase with master and make reinstall mutate on local machine -- I have a suspicion that newest Rails release broke some mutation runs due to lack of DATABASE_URL where one was previously not needed.

def count(specification)
query = read_scope(specification)
limit = specification.limit if specification.limit?
query = query_builder(query, limit: limit)
Copy link
Contributor

@joelvh joelvh Nov 29, 2018

Choose a reason for hiding this comment

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

@mpraglowski I would say just do query = query.take(limit) if specification.limit? and skip query_builder because it does some combining of association data and entity mapping that you don't need to get the count

@mpraglowski mpraglowski force-pushed the size-of-a-stream-to-read branch from bdee7fc to 7d52c25 Compare November 29, 2018 10:38
@mpraglowski mpraglowski merged commit 59103ab into master Nov 29, 2018
@mpraglowski mpraglowski deleted the size-of-a-stream-to-read branch November 29, 2018 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants