mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 09:36:44 +00:00
perf(core): Populate cache only with static webhooks (#16048)
This commit is contained in:
@@ -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() });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user