Skip to content

serialize event count in store function call #1065

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

Merged
merged 1 commit into from
May 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions lib/event_processor/batch_event_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class BatchEventProcessor extends BaseService implements EventProcessor {
private batchSize: number;
private eventStore?: Store<EventWithId>;
private eventCountInStore: Maybe<number> = undefined;
private eventCountWaitPromise: Promise<unknown> = Promise.resolve();
private maxEventsInStore: number = MAX_EVENTS_IN_STORE;
private dispatchRepeater: Repeater;
private failedEventRepeater?: Repeater;
Expand Down Expand Up @@ -264,15 +265,22 @@ export class BatchEventProcessor extends BaseService implements EventProcessor {
}
}

private async findEventCountInStore(): Promise<void> {
private async readEventCountInStore(store: Store<EventWithId>): Promise<void> {
try {
const keys = await store.getKeys();
this.eventCountInStore = keys.length;
} catch (e) {
this.logger?.error(e);
}
}

private async findEventCountInStore(): Promise<unknown> {
if (this.eventStore && this.eventCountInStore === undefined) {
try {
const keys = await this.eventStore.getKeys();
this.eventCountInStore = keys.length;
} catch (e) {
this.logger?.error(e);
}
const store = this.eventStore;
this.eventCountWaitPromise = this.eventCountWaitPromise.then(() => this.readEventCountInStore(store));
return this.eventCountWaitPromise;
}
return Promise.resolve();
}

private async storeEvent(eventWithId: EventWithId): Promise<void> {
Expand Down
Loading