From a18822af0ee974bba783ca3c4b0def65fde04b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Thu, 5 Jun 2025 12:02:06 +0200 Subject: [PATCH] perf(core): Populate cache only with static webhooks (#16048) --- .../@n8n/db/src/repositories/webhook.repository.ts | 10 +++++++++- packages/cli/src/webhooks/webhook.service.ts | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/@n8n/db/src/repositories/webhook.repository.ts b/packages/@n8n/db/src/repositories/webhook.repository.ts index 91372a28b2..6ad9a317cc 100644 --- a/packages/@n8n/db/src/repositories/webhook.repository.ts +++ b/packages/@n8n/db/src/repositories/webhook.repository.ts @@ -1,5 +1,5 @@ import { Service } from '@n8n/di'; -import { DataSource, Repository } from '@n8n/typeorm'; +import { DataSource, IsNull, Repository } from '@n8n/typeorm'; import { WebhookEntity } from '../entities'; @@ -8,4 +8,12 @@ export class WebhookRepository extends Repository { constructor(dataSource: DataSource) { super(WebhookEntity, dataSource.manager); } + + /** + * Retrieve all webhooks whose paths only have static segments, e.g. `{uuid}` or `user/profile`. + * This excludes webhooks having paths with dynamic segments, e.g. `{uuid}/user/:id/posts`. + */ + async getStaticWebhooks() { + return await this.findBy({ webhookId: IsNull() }); + } } diff --git a/packages/cli/src/webhooks/webhook.service.ts b/packages/cli/src/webhooks/webhook.service.ts index 490ae186d3..eb5e173307 100644 --- a/packages/cli/src/webhooks/webhook.service.ts +++ b/packages/cli/src/webhooks/webhook.service.ts @@ -32,11 +32,11 @@ export class WebhookService { ) {} async populateCache() { - const allWebhooks = await this.webhookRepository.find(); + const staticWebhooks = await this.webhookRepository.getStaticWebhooks(); - if (!allWebhooks) return; + if (staticWebhooks.length === 0) return; - void this.cacheService.setMany(allWebhooks.map((w) => [w.cacheKey, w])); + void this.cacheService.setMany(staticWebhooks.map((w) => [w.cacheKey, w])); } async findAll() {