This update improves the throttling mechanism for conversation meta requests to optimize server load and enhance performance. The changes implement differentiated thresholds based on account size - a 2-second throttle for small accounts (≤100 conversations) and a 10-second throttle for large accounts (>100 conversations). Fixes #11178
38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import ConversationMetaThrottleManager from 'dashboard/helper/ConversationMetaThrottleManager';
|
|
import { shouldThrottle } from '../../conversationStats';
|
|
|
|
vi.mock('dashboard/helper/ConversationMetaThrottleManager', () => ({
|
|
default: {
|
|
shouldThrottle: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
describe('shouldThrottle', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it('uses normal threshold for accounts with 100 or fewer conversations', () => {
|
|
shouldThrottle(100);
|
|
expect(ConversationMetaThrottleManager.shouldThrottle).toHaveBeenCalledWith(
|
|
2000
|
|
);
|
|
});
|
|
|
|
it('uses large account threshold for accounts with more than 100 conversations', () => {
|
|
shouldThrottle(101);
|
|
expect(ConversationMetaThrottleManager.shouldThrottle).toHaveBeenCalledWith(
|
|
10000
|
|
);
|
|
});
|
|
|
|
it('returns the throttle value from ConversationMetaThrottleManager', () => {
|
|
ConversationMetaThrottleManager.shouldThrottle.mockReturnValue(true);
|
|
expect(shouldThrottle(50)).toBe(true);
|
|
|
|
ConversationMetaThrottleManager.shouldThrottle.mockReturnValue(false);
|
|
expect(shouldThrottle(150)).toBe(false);
|
|
});
|
|
});
|