From 552aec1773849179740ae1e7e4a18d17e3925220 Mon Sep 17 00:00:00 2001 From: Rizky Date: Wed, 28 Feb 2024 10:02:36 +0700 Subject: [PATCH] wip fix --- app/web/src/nova/prod/base/component.tsx | 32 +++++++++++++----------- app/web/src/nova/prod/root.tsx | 4 +-- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/web/src/nova/prod/base/component.tsx b/app/web/src/nova/prod/base/component.tsx index 75202430..3e1fc389 100644 --- a/app/web/src/nova/prod/base/component.tsx +++ b/app/web/src/nova/prod/base/component.tsx @@ -5,7 +5,7 @@ import { ISection } from "../../../utils/types/section"; import { base } from "./base"; import { prodCache } from "./cache"; -export const scanComponent = async (items: IContent[]) => { +export const scanComponent = async (items: IContent[], use_cache?: boolean) => { const comp = base.comp; for (const item of items) { @@ -17,21 +17,23 @@ export const scanComponent = async (items: IContent[]) => { if (comp.pending.size > 0) { let all_found = true; const founds: any = []; - for (const id of [...comp.pending]) { - const item = await get(`comp-${id}`, prodCache); - if (!item) { - all_found = false; - } - comp.list[id] = item; - founds.push(item); - } - - if (all_found) { + if (!use_cache) { for (const id of [...comp.pending]) { - comp.pending.delete(id); + const item = await get(`comp-${id}`, prodCache); + if (!item) { + all_found = false; + } + comp.list[id] = item; + founds.push(item); + } + + if (all_found) { + for (const id of [...comp.pending]) { + comp.pending.delete(id); + } + await scanComponent(founds, use_cache); + return; } - await scanComponent(founds); - return; } } @@ -49,7 +51,7 @@ export const scanComponent = async (items: IContent[]) => { await set(`comp-${id}`, item, prodCache); } - await scanComponent(Object.values(res)); + await scanComponent(Object.values(res), use_cache); } catch (e) {} } }; diff --git a/app/web/src/nova/prod/root.tsx b/app/web/src/nova/prod/root.tsx index 00d68ebb..5b11f6c6 100644 --- a/app/web/src/nova/prod/root.tsx +++ b/app/web/src/nova/prod/root.tsx @@ -105,7 +105,7 @@ export const Root = () => { root, meta: {}, }; - await scanComponent(root.childs); + await scanComponent(root.childs, !isPreviewProd); rebuildMeta(p.meta, root); base.page.cache[p.id] = p; render(); @@ -198,7 +198,7 @@ export const Root = () => { root: page.root, meta: {}, }; - await scanComponent(page.root.childs); + await scanComponent(page.root.childs, !isPreviewProd); rebuildMeta(p.meta, page.root); base.page.cache[p.id] = p; }