mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-08 03:17:30 -08:00
f53c482939
Story: https://linear.app/n8n/issue/PAY-1188 - Implement Redis hashes on the caching service, based on Micha's work in #7747, adapted from `node-cache-manager-ioredis-yet`. Optimize workflow ownership lookups and manual webhook lookups with Redis hashes. - Simplify the caching service by removing all currently unused methods and options: `enable`, `disable`, `getCache`, `keys`, `keyValues`, `refreshFunctionEach`, `refreshFunctionMany`, `refreshTtl`, etc. - Remove the flag `N8N_CACHE_ENABLED`. Currently some features on `master` are broken with caching disabled, and test webhooks now rely entirely on caching, for multi-main setup support. We originally introduced this flag to protect against excessive memory usage, but total cache usage is low enough that we decided to drop this setting. Apparently this flag was also never documented. - Overall caching service refactor: use generics, reduce branching, add discriminants for cache kinds for better type safety, type caching events, improve readability, remove outdated docs, etc. Also refactor and expand caching service tests. Follow-up to: https://github.com/n8n-io/n8n/pull/8176 --------- Co-authored-by: Michael Auerswald <michael.auerswald@gmail.com>
53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import { Service } from 'typedi';
|
|
import { CacheService } from '@/services/cache/cache.service';
|
|
import { jsonParse } from 'n8n-workflow';
|
|
|
|
type ActivationErrors = {
|
|
[workflowId: string]: string; // error message
|
|
};
|
|
|
|
@Service()
|
|
export class ActivationErrorsService {
|
|
private readonly cacheKey = 'workflow-activation-errors';
|
|
|
|
constructor(private readonly cacheService: CacheService) {}
|
|
|
|
async set(workflowId: string, errorMessage: string) {
|
|
const errors = await this.getAll();
|
|
|
|
errors[workflowId] = errorMessage;
|
|
|
|
await this.cacheService.set(this.cacheKey, JSON.stringify(errors));
|
|
}
|
|
|
|
async unset(workflowId: string) {
|
|
const errors = await this.getAll();
|
|
|
|
if (Object.keys(errors).length === 0) return;
|
|
|
|
delete errors[workflowId];
|
|
|
|
await this.cacheService.set(this.cacheKey, JSON.stringify(errors));
|
|
}
|
|
|
|
async get(workflowId: string) {
|
|
const errors = await this.getAll();
|
|
|
|
if (Object.keys(errors).length === 0) return null;
|
|
|
|
return errors[workflowId];
|
|
}
|
|
|
|
async getAll() {
|
|
const errors = await this.cacheService.get<string>(this.cacheKey);
|
|
|
|
if (!errors) return {};
|
|
|
|
return jsonParse<ActivationErrors>(errors);
|
|
}
|
|
|
|
async clearAll() {
|
|
await this.cacheService.delete(this.cacheKey);
|
|
}
|
|
}
|