From b7d0334f141f4d880b1d4428b4d9e72186d7c2ff Mon Sep 17 00:00:00 2001 From: bnechyporenko Date: Sat, 2 Nov 2024 14:13:48 +0100 Subject: [PATCH] Cleaning up event subscriptions after the max age window Signed-off-by: bnechyporenko --- .changeset/silly-kiwis-destroy.md | 5 +++++ .../events-backend/src/service/hub/DatabaseEventBusStore.ts | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/silly-kiwis-destroy.md diff --git a/.changeset/silly-kiwis-destroy.md b/.changeset/silly-kiwis-destroy.md new file mode 100644 index 0000000000..31bdf4560b --- /dev/null +++ b/.changeset/silly-kiwis-destroy.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-events-backend': patch +--- + +Cleaning up event subscriptions after the max age window diff --git a/plugins/events-backend/src/service/hub/DatabaseEventBusStore.ts b/plugins/events-backend/src/service/hub/DatabaseEventBusStore.ts index 107dabfc27..6572bdbfc6 100644 --- a/plugins/events-backend/src/service/hub/DatabaseEventBusStore.ts +++ b/plugins/events-backend/src/service/hub/DatabaseEventBusStore.ts @@ -602,7 +602,9 @@ export class DatabaseEventBusStore implements EventBusStore { if (minId === null) { // No events left, remove all subscribers. This can happen if no events // are published within the max age window. - subscriberCount = await this.#db(TABLE_SUBSCRIPTIONS).delete(); + subscriberCount = await this.#db(TABLE_SUBSCRIPTIONS) + .where('updated_at', '<', new Date(Date.now() - this.#windowMaxAge)) + .delete(); } else { subscriberCount = await this.#db(TABLE_SUBSCRIPTIONS) .delete()