From c6e872654368d314d6e83a74afd49e2040342f29 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sat, 25 May 2024 08:36:04 +0200 Subject: [PATCH] events-backend: lock subscription row when reading Signed-off-by: Patrik Oldsberg --- .../events-backend/src/service/hub/DatabaseEventBusStore.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/events-backend/src/service/hub/DatabaseEventBusStore.ts b/plugins/events-backend/src/service/hub/DatabaseEventBusStore.ts index 4e571f71f0..600a038793 100644 --- a/plugins/events-backend/src/service/hub/DatabaseEventBusStore.ts +++ b/plugins/events-backend/src/service/hub/DatabaseEventBusStore.ts @@ -324,7 +324,9 @@ export class DatabaseEventBusStore implements EventBusStore { async readSubscription(id: string): Promise<{ events: EventParams[] }> { const result = await this.#db(TABLE_SUBSCRIPTIONS) // Read the target subscription so that we can use the read marker and topics - .with('sub', q => q.select().from(TABLE_SUBSCRIPTIONS).where({ id })) + .with('sub', q => + q.select().from(TABLE_SUBSCRIPTIONS).where({ id }).forUpdate(), + ) // Read the next batch of events for the subscription from its read marker .with('events', q => q