For large accounts with huge volumes of messages, it can be very wasteful to make the meta request so often. It also puts un-necessary load on the DB bombarding it with so many requests. This PR fixes it by throttling the requests to 5 seconds for all users with more than 1000 accessible chats. ### Why not cache this value in the backend? Well, it's a bit tricky, since a user can have different permissions over inboxes and can see different chats, maintaining a cache for each of them is not effective, besides the requests will reach the server anyway.
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
import axios from 'axios';
|
|
import { actions } from '../../conversationStats';
|
|
import * as types from '../../../mutation-types';
|
|
|
|
const commit = vi.fn();
|
|
global.axios = axios;
|
|
vi.mock('axios');
|
|
|
|
describe('#actions', () => {
|
|
describe('#get', () => {
|
|
it('sends correct mutations if API is success', async () => {
|
|
axios.get.mockResolvedValue({ data: { meta: { mine_count: 1 } } });
|
|
await actions.get(
|
|
{ commit, state: { updatedOn: null } },
|
|
{ inboxId: 1, assigneeTpe: 'me', status: 'open' }
|
|
);
|
|
expect(commit.mock.calls).toEqual([
|
|
[types.default.SET_CONV_TAB_META, { mine_count: 1 }],
|
|
]);
|
|
});
|
|
it('sends correct actions if API is error', async () => {
|
|
axios.get.mockRejectedValue({ message: 'Incorrect header' });
|
|
await actions.get(
|
|
{ commit, state: { updatedOn: null } },
|
|
{ inboxId: 1, assigneeTpe: 'me', status: 'open' }
|
|
);
|
|
expect(commit.mock.calls).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe('#set', () => {
|
|
it('sends correct mutations', async () => {
|
|
actions.set(
|
|
{ commit },
|
|
{ mine_count: 1, unassigned_count: 1, all_count: 2 }
|
|
);
|
|
expect(commit.mock.calls).toEqual([
|
|
[
|
|
types.default.SET_CONV_TAB_META,
|
|
{ mine_count: 1, unassigned_count: 1, all_count: 2 },
|
|
],
|
|
]);
|
|
});
|
|
});
|
|
});
|