refactor: add detailed logging for productCache checks in Content component to aid in debugging category data fetching

This commit is contained in:
sebseb7
2025-07-23 09:54:58 +02:00
parent cd4d124e22
commit abf94eba86

View File

@@ -202,6 +202,16 @@ class Content extends Component {
}
componentDidMount() {
// Debug check for window.productCache
console.log("Content componentDidMount - window.productCache exists:", !!window.productCache);
if (window.productCache) {
console.log("Content componentDidMount - window.productCache keys:", Object.keys(window.productCache));
if (window.productCache["categoryTree_209"]) {
console.log("Content componentDidMount - categoryTree_209.categoryTree exists:",
!!window.productCache["categoryTree_209"].categoryTree);
}
}
if(this.props.params.categoryId) {this.setState({loaded: false, unfilteredProducts: [], filteredProducts: [], attributes: [], categoryName: null, childCategories: []}, () => {
this.fetchCategoryData(this.props.params.categoryId);
})}
@@ -259,15 +269,29 @@ class Content extends Component {
fetchCategoryData(categoryId) {
// Direct check for the specific cache key mentioned in the requirement
const hasCategoryTree = window.productCache && window.productCache["categoryTree_209"];
console.log("Checking for category tree in cache");
console.log("window.productCache exists:", !!window.productCache);
if (window.productCache) {
console.log("window.productCache keys:", Object.keys(window.productCache));
console.log("categoryTree_209 exists:", !!window.productCache["categoryTree_209"]);
if (window.productCache["categoryTree_209"]) {
console.log("categoryTree exists:", !!window.productCache["categoryTree_209"].categoryTree);
}
}
// Check for specific category data in cache
const cachedData = getCachedCategoryData(categoryId);
// If we have the category tree data, use it and don't query socket.io
if (hasCategoryTree) {
console.log("Found categoryTree_209 in cache");
// IMPORTANT: Check for the exact structure mentioned in the requirement
// window.productCache = {"categoryTree_209":{"categoryTree": ...}}
if (typeof window.productCache === 'object' &&
window.productCache !== null &&
typeof window.productCache["categoryTree_209"] === 'object' &&
window.productCache["categoryTree_209"] !== null &&
typeof window.productCache["categoryTree_209"].categoryTree === 'object' &&
window.productCache["categoryTree_209"].categoryTree !== null) {
console.log("Found categoryTree_209.categoryTree in cache");
// Check for specific category data in cache
const cachedData = getCachedCategoryData(categoryId);
if (cachedData) {
console.log("Using cached category data for", categoryId);
@@ -286,6 +310,8 @@ class Content extends Component {
return;
}
}
console.log("No category tree found in cache, proceeding with socket.io query");
// Only if we don't have the category tree in cache, proceed with socket.io query
console.log(`productList:${categoryId}`);