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