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

multiple snapshots: how to do getFromSnapshot using version #24

Closed
0xgeert opened this issue Nov 17, 2014 · 5 comments
Closed

multiple snapshots: how to do getFromSnapshot using version #24

0xgeert opened this issue Nov 17, 2014 · 5 comments

Comments

@0xgeert
Copy link

0xgeert commented Nov 17, 2014

Browsing through the docs and this looks great.

One thing that caught my eye, is that I want to create a new snapshot after N events have happened. This results in M snapshots over time that I want to be versioned.

createSnapshot allows me to define an optional version. Normally I'd like to retrieve the latest snapshot (is there a shortcut to get to the latest without defining a version ? ) but sometimes I want to fetch an arbitrary version. However, getFromSnapshot (at least from the docs) doesn't seem to allow to pass version

How to do this?

@adrai
Copy link
Contributor

adrai commented Nov 17, 2014

getFromSnapshot simply returns a snapshot and depending on the version describing that snapshot you can handle it... for example you can convert it... i.e. https://github.com/adrai/node-cqrs-domain/blob/master/lib/definitions/aggregate.js#L652

@adrai adrai closed this as completed Mar 24, 2015
@rehia
Copy link
Contributor

rehia commented Nov 2, 2016

Hi @adrai,

Instead of creating a new issue, I prefer to ask my question here.
Actually, I have the same question: How could I easily get only the latest snapshot (with only the new events), without knowing the current revision ?

I'm using redis store, and it seems that the snapshots are all scanned by default (using revMax === -1).
I was using snapshots to enhance performance because of a lot of events on an aggregate. But it won't if all snapshots are scanned.
And I don't have the current revision of the aggregate because the time I'm reloading the aggregate form a snapshot.

Looking at the code of redis storage, I thought passing 1 as revMax would avoid many useless GET on redis, because of these lines:
https://github.com/adrai/node-eventstore/blob/831698514af8bfb0d6d8c0f65e139250e1bb7b3a/lib/databases/redis.js#L579-L585
The snapshot keys are reduced to the last snapshot key.

But once the snapshot is loaded, it is filtered because its revision (usually above 1) doesn't fit this filter:
https://github.com/adrai/node-eventstore/blob/831698514af8bfb0d6d8c0f65e139250e1bb7b3a/lib/databases/redis.js#L606

So I feel like, if I want the latest snapshot, I need to pass the the "real" revision, but by doing this, all of the snapshots will be loaded, hence causing some "n+1 selects" issue with no need.

Correct me if I'm wrong. Thanks for your awesome work. I would love to help.

@rehia
Copy link
Contributor

rehia commented Nov 2, 2016

By the way, we can also reverse the question by asking: how is it possible to get the snapshot of revision 1, if there is already a snapshot for revision 4 ?

@rehia
Copy link
Contributor

rehia commented Nov 2, 2016

Finally made a pull request to improve the way snapshots are loaded.

@adrai
Copy link
Contributor

adrai commented Nov 2, 2016

Sorry, had no time to take a look at it...
Will look at it asap.
Thanks for your contribution.

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

No branches or pull requests

3 participants