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() { 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: []}, () => { if(this.props.params.categoryId) {this.setState({loaded: false, unfilteredProducts: [], filteredProducts: [], attributes: [], categoryName: null, childCategories: []}, () => {
this.fetchCategoryData(this.props.params.categoryId); this.fetchCategoryData(this.props.params.categoryId);
})} })}
@@ -259,15 +269,29 @@ class Content extends Component {
fetchCategoryData(categoryId) { fetchCategoryData(categoryId) {
// Direct check for the specific cache key mentioned in the requirement console.log("Checking for category tree in cache");
const hasCategoryTree = window.productCache && window.productCache["categoryTree_209"]; 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 // IMPORTANT: Check for the exact structure mentioned in the requirement
const cachedData = getCachedCategoryData(categoryId); // 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) {
// If we have the category tree data, use it and don't query socket.io console.log("Found categoryTree_209.categoryTree in cache");
if (hasCategoryTree) {
console.log("Found categoryTree_209 in cache"); // Check for specific category data in cache
const cachedData = getCachedCategoryData(categoryId);
if (cachedData) { if (cachedData) {
console.log("Using cached category data for", categoryId); console.log("Using cached category data for", categoryId);
@@ -287,6 +311,8 @@ class Content extends Component {
} }
} }
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 // Only if we don't have the category tree in cache, proceed with socket.io query
console.log(`productList:${categoryId}`); console.log(`productList:${categoryId}`);
window.socketManager.off(`productList:${categoryId}`); window.socketManager.off(`productList:${categoryId}`);