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,4 +1,7 @@
|
||||
import { getMostReadArticles } from 'widget/api/article';
|
||||
import { getFromCache, setCache } from 'shared/helpers/cache';
|
||||
|
||||
const CACHE_KEY_PREFIX = 'chatwoot_most_read_articles_';
|
||||
|
||||
const state = {
|
||||
records: [],
|
||||
@@ -20,9 +23,16 @@ export const actions = {
|
||||
commit('setError', false);
|
||||
|
||||
try {
|
||||
const cachedData = getFromCache(`${CACHE_KEY_PREFIX}${slug}_${locale}`);
|
||||
if (cachedData) {
|
||||
commit('setArticles', cachedData);
|
||||
return;
|
||||
}
|
||||
|
||||
const { data } = await getMostReadArticles(slug, locale);
|
||||
const { payload = [] } = data;
|
||||
|
||||
setCache(`${CACHE_KEY_PREFIX}${slug}_${locale}`, payload);
|
||||
if (payload.length) {
|
||||
commit('setArticles', payload);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user