fix: Update throttle for /meta endpoints, will call every 2s for small account, 10s for large accounts (#11190)
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
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user