refactor: enhance logging and cache checks in SharedCarousel and CategoryList components to improve data fetching clarity and performance
This commit is contained in:
@@ -85,12 +85,14 @@ const SharedCarousel = () => {
|
||||
|
||||
// Use cache if available
|
||||
if (categoryTree) {
|
||||
console.log('SharedCarousel: Using cached category tree');
|
||||
setRootCategories(processCategoryTree(categoryTree));
|
||||
return;
|
||||
}
|
||||
|
||||
// Only fetch if needed
|
||||
if (rootCategories.length === 0 && typeof window !== "undefined") {
|
||||
console.log('SharedCarousel: Cache not found, fetching from socket');
|
||||
window.socketManager.emit("categoryList", { categoryId: 209, language: currentLanguage, requestTranslation: true }, (response) => {
|
||||
if (response && response.success) {
|
||||
// Use translated data if available, otherwise fall back to original
|
||||
|
||||
@@ -163,6 +163,7 @@ class CategoryList extends Component {
|
||||
|
||||
fetchCategories = () => {
|
||||
if (this.state.fetchedCategories) {
|
||||
console.log('Categories already fetched, skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -179,12 +180,14 @@ class CategoryList extends Component {
|
||||
// USE THE CACHE directly - if it has data, use it
|
||||
const categoryTree = windowObj.productCache[cacheKey]?.categoryTree;
|
||||
if (categoryTree) {
|
||||
console.log('CategoryList: Using cached category tree');
|
||||
this.processCategoryTree(categoryTree);
|
||||
this.setState({ fetchedCategories: true });
|
||||
return;
|
||||
}
|
||||
|
||||
// No cache, so fetch
|
||||
console.log('CategoryList: Cache not found, fetching from socket');
|
||||
windowObj.productCache[cacheKey] = { fetching: true, timestamp: Date.now() };
|
||||
this.setState({ fetchedCategories: true });
|
||||
window.socketManager.emit("categoryList", { categoryId: 209, language: currentLanguage, requestTranslation: true }, (response) => {
|
||||
|
||||
Reference in New Issue
Block a user