@tuanltntu/n8n-nodes-bitrix24
Version:
Comprehensive n8n community node for Bitrix24 API integration with CRM, Tasks, Chat, Telephony, and more
82 lines (81 loc) • 2.67 kB
TypeScript
import { INodePropertyOptions } from "n8n-workflow";
/**
* Utility class to optimize loadOptions performance with smart debouncing and caching
* This helps prevent excessive API calls during form input validation
*
* Vấn đề chính: Mỗi keystroke đều load all fields từ Bitrix24 API
* Giải pháp: Smart caching + debouncing + chỉ reload khi thực sự cần thiết
*/
export declare class LoadOptionsOptimizer {
private static cache;
private static pendingRequests;
private static debounceTimers;
private static lastParams;
private static readonly DEFAULT_TTL;
private static readonly DEFAULT_DEBOUNCE_DELAY;
/**
* Get cached options if available and not expired
*/
private static getCachedOptions;
/**
* Set options in cache with TTL
*/
private static setCachedOptions;
/**
* Generate cache key based on method name and parameters
*/
private static generateCacheKey;
/**
* Clear expired cache entries
*/
private static cleanupExpiredCache;
/**
* Get last parameters for a method
*/
private static getLastParams;
/**
* Set last parameters for a method
*/
private static setLastParams;
/**
* Check if parameters have changed significantly
* Đây là key để fix vấn đề keystroke - chỉ reload khi thực sự cần thiết
*/
private static hasSignificantParamsChange;
/**
* Smart loadOptions method with intelligent caching and debouncing
* @param methodName - Name of the loadOptions method
* @param params - Parameters for the method
* @param loadFunction - The actual loading function
* @param options - Configuration options
*/
static loadOptionsWithOptimization<T extends Record<string, any>>(methodName: string, params: T, loadFunction: (params: T) => Promise<INodePropertyOptions[]>, options?: {
debounceDelay?: number;
cacheTTL?: number;
enableCache?: boolean;
enableDebounce?: boolean;
smartDebounce?: boolean;
minParamsChange?: boolean;
}): Promise<INodePropertyOptions[]>;
/**
* Execute the actual loading function with caching
*/
private static executeLoadFunction;
/**
* Clear all cache and pending requests
*/
static clearAll(): void;
/**
* Clear cache for specific method
*/
static clearCacheForMethod(methodName: string): void;
/**
* Get cache statistics
*/
static getCacheStats(): {
size: number;
pendingRequests: number;
activeTimers: number;
lastParams: number;
};
}