GithubHelp home page GithubHelp logo

Comments (4)

yarbelk avatar yarbelk commented on May 18, 2024 3

Yup, that is the method I was talking of - it switches the argument order from the @singledispatch - which needs F(event:E, state:S) -> S to F'(state:S, event:E) -> S, which is needed by reduce. This took me a bit of time to catch, as its a rather subtle difference when you're just reading through the code.

I added some comments to PR #60 , I like the refactors: it feels cleaner.

Looking forward to the next release.

from eventsourcing.

yarbelkgazia avatar yarbelkgazia commented on May 18, 2024

Actually, you need to use the classmethod on the repository, which has the call order reversed so it works with reduce, and sets up the class if the initial state is None. Wasn't clear to me initially. should document this.

from eventsourcing.

johnbywater avatar johnbywater commented on May 18, 2024

On the develop branch, the ExampleApplication enables snapshotting by constructing a snapshot strategy, then passing it to the event sourced repository. That causes the repository to check for a snapshot before it gets all the events. And if there is a snapshot, it only gets the events that were applied after the snapshot was taken. It also uses older snapshots when getting an entity at a historical version. There's a test covering it.

        self.example_repo = ExampleRepository(
            event_store=self.version_entity_event_store,
            snapshot_strategy=self.snapshot_strategy,
        )

However, I had two issues with this code: firstly snapshots used timestamps not version numbers, and also there wasn't a snapshotting policy to automatically create snapshots.

So I just reworked the snapshotting. The snapshot records are now in a dedicated table. Snapshots use integers which correspond to event entity version attribute, rather than event timestamps. I added a section to the README file about using snapshots (will move it to the new docs when the code snippets in the new docs are covered with a test, with something like the test_readme.py). And in that new section added an example snapshotting policy that automatically takes a snapshot every five events.

The changes are in PR #60. Let me know what you think?

(Not sure which class method you meant, was it mutate()? I think it's correct that the snapshot events aren't supported by the mutator function, if that's what was happening in your first comment.)

from eventsourcing.

johnbywater avatar johnbywater commented on May 18, 2024

Just to link things up, there is now a page in the documentation about snapshotting, here:

http://eventsourcing.readthedocs.io/en/latest/topics/user_guide/snapshotting.html

from eventsourcing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.