Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
670ab2400a | ||
|
|
4a800eb8d1 | ||
|
|
1bf1075427 | ||
|
|
4b4d9f8f7c | ||
|
|
49ee147fe3 |
@@ -32,6 +32,7 @@ class ConversationFinder
|
||||
def initialize(current_user, params)
|
||||
@current_user = current_user
|
||||
@current_account = current_user.account
|
||||
@is_admin = current_account.account_users.find_by(user_id: current_user.id)&.administrator?
|
||||
@params = params
|
||||
end
|
||||
|
||||
@@ -86,7 +87,8 @@ class ConversationFinder
|
||||
end
|
||||
|
||||
def find_all_conversations
|
||||
@conversations = current_account.conversations.where(inbox_id: @inbox_ids)
|
||||
@conversations = current_account.conversations
|
||||
@conversations = @conversations.where(inbox_id: @inbox_ids) unless @is_admin
|
||||
filter_by_conversation_type if params[:conversation_type]
|
||||
@conversations
|
||||
end
|
||||
|
||||
@@ -61,7 +61,7 @@ import {
|
||||
getUserPermissions,
|
||||
filterItemsByPermission,
|
||||
} from 'dashboard/helper/permissionsHelper.js';
|
||||
import { matchesFilters } from '../store/modules/conversations/helpers/filterHelpers';
|
||||
// import { matchesFilters } from '../store/modules/conversations/helpers/filterHelpers';
|
||||
import { CONVERSATION_EVENTS } from '../helper/AnalyticsHelper/events';
|
||||
import { ASSIGNEE_TYPE_TAB_PERMISSIONS } from 'dashboard/constants/permissions.js';
|
||||
|
||||
@@ -106,7 +106,7 @@ const advancedFilterTypes = ref(
|
||||
);
|
||||
|
||||
const currentUser = useMapGetter('getCurrentUser');
|
||||
const chatLists = useMapGetter('getFilteredConversations');
|
||||
const chatLists = useMapGetter('getAllConversations');
|
||||
const mineChatsList = useMapGetter('getMineChats');
|
||||
const allChatList = useMapGetter('getAllStatusChats');
|
||||
const unAssignedChatsList = useMapGetter('getUnAssignedChats');
|
||||
@@ -326,12 +326,12 @@ const conversationList = computed(() => {
|
||||
localConversationList = [...chatLists.value];
|
||||
}
|
||||
|
||||
if (activeFolder.value) {
|
||||
const { payload } = activeFolder.value.query;
|
||||
localConversationList = localConversationList.filter(conversation => {
|
||||
return matchesFilters(conversation, payload);
|
||||
});
|
||||
}
|
||||
// if (activeFolder.value) {
|
||||
// const { payload } = activeFolder.value.query;
|
||||
// localConversationList = localConversationList.filter(conversation => {
|
||||
// return matchesFilters(conversation, payload);
|
||||
// });
|
||||
// }
|
||||
|
||||
return localConversationList;
|
||||
});
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
class ConversationMetaThrottleManager {
|
||||
constructor() {
|
||||
this.lastUpdatedTime = null;
|
||||
}
|
||||
|
||||
shouldThrottle(threshold = 10000) {
|
||||
if (!this.lastUpdatedTime) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const currentTime = new Date().getTime();
|
||||
const lastUpdatedTime = new Date(this.lastUpdatedTime).getTime();
|
||||
|
||||
if (currentTime - lastUpdatedTime < threshold) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
markUpdate() {
|
||||
this.lastUpdatedTime = new Date();
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.lastUpdatedTime = null;
|
||||
}
|
||||
}
|
||||
|
||||
export default new ConversationMetaThrottleManager();
|
||||
@@ -0,0 +1,34 @@
|
||||
import ConversationMetaThrottleManager from '../ConversationMetaThrottleManager';
|
||||
|
||||
describe('ConversationMetaThrottleManager', () => {
|
||||
beforeEach(() => {
|
||||
// Reset the lastUpdatedTime before each test
|
||||
ConversationMetaThrottleManager.lastUpdatedTime = null;
|
||||
});
|
||||
|
||||
describe('shouldThrottle', () => {
|
||||
it('returns false when lastUpdatedTime is not set', () => {
|
||||
expect(ConversationMetaThrottleManager.shouldThrottle()).toBe(false);
|
||||
});
|
||||
|
||||
it('returns true when time difference is less than threshold', () => {
|
||||
ConversationMetaThrottleManager.markUpdate();
|
||||
expect(ConversationMetaThrottleManager.shouldThrottle()).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false when time difference is more than threshold', () => {
|
||||
ConversationMetaThrottleManager.lastUpdatedTime = new Date(
|
||||
Date.now() - 11000
|
||||
);
|
||||
expect(ConversationMetaThrottleManager.shouldThrottle()).toBe(false);
|
||||
});
|
||||
|
||||
it('respects custom threshold value', () => {
|
||||
ConversationMetaThrottleManager.lastUpdatedTime = new Date(
|
||||
Date.now() - 5000
|
||||
);
|
||||
expect(ConversationMetaThrottleManager.shouldThrottle(3000)).toBe(false);
|
||||
expect(ConversationMetaThrottleManager.shouldThrottle(6000)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,28 +1,40 @@
|
||||
import types from '../mutation-types';
|
||||
import ConversationApi from '../../api/inbox/conversation';
|
||||
|
||||
import ConversationMetaThrottleManager from 'dashboard/helper/ConversationMetaThrottleManager';
|
||||
|
||||
const state = {
|
||||
mineCount: 0,
|
||||
unAssignedCount: 0,
|
||||
allCount: 0,
|
||||
updatedOn: null,
|
||||
};
|
||||
|
||||
export const getters = {
|
||||
getStats: $state => $state,
|
||||
};
|
||||
|
||||
export const shouldThrottle = conversationCount => {
|
||||
// The threshold for throttling is different for normal users and large accounts
|
||||
// Normal users: 2 seconds
|
||||
// Large accounts: 10 seconds
|
||||
// We would only update the conversation stats based on the threshold above.
|
||||
// This is done to reduce the number of /meta request made to the server.
|
||||
const NORMAL_USER_THRESHOLD = 500;
|
||||
const LARGE_ACCOUNT_THRESHOLD = 10000;
|
||||
|
||||
const threshold =
|
||||
conversationCount > 100 ? LARGE_ACCOUNT_THRESHOLD : NORMAL_USER_THRESHOLD;
|
||||
return ConversationMetaThrottleManager.shouldThrottle(threshold);
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
get: async ({ commit, state: $state }, params) => {
|
||||
const currentTime = new Date();
|
||||
const lastUpdatedTime = new Date($state.updatedOn);
|
||||
|
||||
// Skip large accounts from making too many requests
|
||||
if (currentTime - lastUpdatedTime < 10000 && $state.allCount > 100) {
|
||||
if (shouldThrottle($state.allCount)) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn('Skipping conversation meta fetch');
|
||||
console.warn('Throttle /meta fetch, will resume after threshold');
|
||||
return;
|
||||
}
|
||||
ConversationMetaThrottleManager.markUpdate();
|
||||
|
||||
try {
|
||||
const response = await ConversationApi.meta(params);
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
html,
|
||||
body {
|
||||
@apply antialiased h-full bg-n-background;
|
||||
@apply antialiased h-full;
|
||||
}
|
||||
|
||||
.is-mobile {
|
||||
|
||||
Reference in New Issue
Block a user