perf(core): Populate cache only with static webhooks (#16048)

This commit is contained in:
Iván Ovejero
2025-06-05 12:02:06 +02:00
committed by GitHub
parent 07b12a41a4
commit a18822af0e
2 changed files with 12 additions and 4 deletions

View File

@@ -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<WebhookEntity> {
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() });
}
}

View File

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