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

Snapshot Discussion #181

Open
jeremycare opened this issue Jan 16, 2024 · 0 comments
Open

Snapshot Discussion #181

jeremycare opened this issue Jan 16, 2024 · 0 comments

Comments

@jeremycare
Copy link

Hey,

We're currently preparing to add snapshots to our projects, it's not implemented yet in Castore.

We are planning on implementing something similar to:

  public async getAggregate(id: string): Promise<AGGREGATE_CLASS | undefined> {
    const snapshot: { version: number, aggregateState: $AGGREGATE } | undefined = await this.getSnapshot(id);

    const version = snapshot ? snapshot.version : 0;
    const aggregateState = snapshot ? snapshot.aggregateState : {} as $AGGREGATE;

    const { events } = await this.castoreEventStore.getEvents(id, { minVersion: version || 0 });
    // cast to any because it's not typed correctly EVENT_DETAIL[] vs $EVENT_DETAIL[]
    const aggregate = this.castoreEventStore.buildAggregate(events as any, aggregateState);

    if (aggregate === undefined) {
      return undefined;
    }

    // this create an AggregateClass from the state
    return this.factory(aggregate);
  }

Where snapshots are stored listening to StateCarryingEvents.

But my main concern is about snapshot invalidations, If you have any recommendations for that?

We are also considering adding an AggregateReducerVersion in our class (that we could increment manually) to invalidate snapshots built with another reducer, but it seems tricky to maintain something like that manually.

Do you already have some idea of the future implementation of snapshots in Castore we could take inspiration on?
What have been the issues you were facing implementing it in the past?

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

1 participant