chore: Add cache to improve widget performance (#11163)
- Add dynamic importing for routes. - Added caching for `campaign`, `articles` and `inbox_members` API end points. --------- Co-authored-by: Pranav <pranavrajs@gmail.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { getAvailableAgents } from 'widget/api/agent';
|
||||
import * as MutationHelpers from 'shared/helpers/vuex/mutationHelpers';
|
||||
import { getFromCache, setCache } from 'shared/helpers/cache';
|
||||
|
||||
const state = {
|
||||
records: [],
|
||||
@@ -15,11 +16,22 @@ export const getters = {
|
||||
$state.records.filter(agent => agent.availability_status === 'online'),
|
||||
};
|
||||
|
||||
const CACHE_KEY_PREFIX = 'chatwoot_available_agents_';
|
||||
|
||||
export const actions = {
|
||||
fetchAvailableAgents: async ({ commit }, websiteToken) => {
|
||||
try {
|
||||
const cachedData = getFromCache(`${CACHE_KEY_PREFIX}${websiteToken}`);
|
||||
if (cachedData) {
|
||||
commit('setAgents', cachedData);
|
||||
commit('setError', false);
|
||||
commit('setHasFetched', true);
|
||||
return;
|
||||
}
|
||||
|
||||
const { data } = await getAvailableAgents(websiteToken);
|
||||
const { payload = [] } = data;
|
||||
setCache(`${CACHE_KEY_PREFIX}${websiteToken}`, payload);
|
||||
commit('setAgents', payload);
|
||||
commit('setError', false);
|
||||
commit('setHasFetched', true);
|
||||
|
||||
Reference in New Issue
Block a user