refactor: implement CategoryService for category data management and update caching logic in prerender and renderer components
This commit is contained in:
@@ -19,6 +19,24 @@ global.Blob = class MockBlob {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CategoryService {
|
||||||
|
constructor() {
|
||||||
|
this.get = this.get.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
getSync(categoryId, language = "de") {
|
||||||
|
const cacheKey = `${categoryId}_${language}`;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async get(categoryId, language = "de") {
|
||||||
|
const cacheKey = `${categoryId}_${language}`;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
global.window.categoryService = new CategoryService();
|
||||||
|
|
||||||
|
|
||||||
// Import modules
|
// Import modules
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
@@ -350,14 +368,14 @@ const renderProductsInParallel = async (allProductsArray, maxWorkers, totalProdu
|
|||||||
|
|
||||||
const renderApp = async (categoryData, socket) => {
|
const renderApp = async (categoryData, socket) => {
|
||||||
if (categoryData) {
|
if (categoryData) {
|
||||||
global.window.productCache = {
|
global.window.categoryCache = {
|
||||||
categoryTree_209: { categoryTree: categoryData, timestamp: Date.now() },
|
"209_de": categoryData,
|
||||||
};
|
};
|
||||||
// @note Make cache available to components during rendering
|
// @note Make cache available to components during rendering
|
||||||
global.productCache = global.window.productCache;
|
global.categoryCache = global.window.categoryCache;
|
||||||
} else {
|
} else {
|
||||||
global.window.productCache = {};
|
global.window.categoryCache = {};
|
||||||
global.productCache = {};
|
global.categoryCache = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to call renderPage with config
|
// Helper to call renderPage with config
|
||||||
|
|||||||
@@ -173,18 +173,18 @@ const renderPage = (
|
|||||||
|
|
||||||
// @note Create script to populate window.productCache with ONLY the static category tree
|
// @note Create script to populate window.productCache with ONLY the static category tree
|
||||||
let productCacheScript = '';
|
let productCacheScript = '';
|
||||||
if (typeof global !== "undefined" && global.window && global.window.productCache) {
|
if (typeof global !== "undefined" && global.window && global.window.categoryCache) {
|
||||||
// Only include the static categoryTree_209, not any dynamic data that gets added during rendering
|
// Only include the static categoryTree_209, not any dynamic data that gets added during rendering
|
||||||
const staticCache = {};
|
const staticCache = {};
|
||||||
if (global.window.productCache.categoryTree_209) {
|
if (global.window.categoryCache["209_de"]) {
|
||||||
staticCache.categoryTree_209 = global.window.productCache.categoryTree_209;
|
staticCache["209_de"] = global.window.categoryCache["209_de"];
|
||||||
}
|
}
|
||||||
|
|
||||||
const staticCacheData = JSON.stringify(staticCache);
|
const staticCacheData = JSON.stringify(staticCache);
|
||||||
productCacheScript = `
|
productCacheScript = `
|
||||||
<script>
|
<script>
|
||||||
// Populate window.productCache with static category tree only
|
// Populate window.categoryCache with static category tree only
|
||||||
window.productCache = ${staticCacheData};
|
window.categoryCache = ${staticCacheData};
|
||||||
</script>
|
</script>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -300,6 +300,7 @@ class Footer extends Component {
|
|||||||
alt="Google Reviews"
|
alt="Google Reviews"
|
||||||
sx={{
|
sx={{
|
||||||
height: { xs: 50, md: 60 },
|
height: { xs: 50, md: 60 },
|
||||||
|
width: { xs: 105, md: 126 },
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
transition: 'all 2s ease',
|
transition: 'all 2s ease',
|
||||||
'&:hover': {
|
'&:hover': {
|
||||||
@@ -329,6 +330,7 @@ class Footer extends Component {
|
|||||||
alt="Google Maps"
|
alt="Google Maps"
|
||||||
sx={{
|
sx={{
|
||||||
height: { xs: 40, md: 50 },
|
height: { xs: 40, md: 50 },
|
||||||
|
width: { xs: 38, md: 49 },
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
transition: 'all 2s ease',
|
transition: 'all 2s ease',
|
||||||
filter: 'drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3))',
|
filter: 'drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3))',
|
||||||
|
|||||||
Reference in New Issue
Block a user