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()