wip fix
This commit is contained in:
parent
2b9c360770
commit
dd67ef0c86
File diff suppressed because one or more lines are too long
|
|
@ -1,3 +0,0 @@
|
||||||
import { createStore } from "idb-keyval";
|
|
||||||
|
|
||||||
export const prodCache = createStore(`prasi-prod`, `prasi-cache-prod`);
|
|
||||||
|
|
@ -3,9 +3,8 @@ import { IContent } from "../../../utils/types/general";
|
||||||
import { IItem } from "../../../utils/types/item";
|
import { IItem } from "../../../utils/types/item";
|
||||||
import { ISection } from "../../../utils/types/section";
|
import { ISection } from "../../../utils/types/section";
|
||||||
import { base } from "./base";
|
import { base } from "./base";
|
||||||
import { prodCache } from "./cache";
|
|
||||||
|
|
||||||
export const scanComponent = async (items: IContent[], use_cache?: boolean) => {
|
export const scanComponent = async (items: IContent[]) => {
|
||||||
const comp = base.comp;
|
const comp = base.comp;
|
||||||
|
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
|
|
@ -17,23 +16,12 @@ export const scanComponent = async (items: IContent[], use_cache?: boolean) => {
|
||||||
if (comp.pending.size > 0) {
|
if (comp.pending.size > 0) {
|
||||||
let all_found = true;
|
let all_found = true;
|
||||||
const founds: any = [];
|
const founds: any = [];
|
||||||
if (use_cache !== false) {
|
if (all_found) {
|
||||||
for (const id of [...comp.pending]) {
|
for (const id of [...comp.pending]) {
|
||||||
const item = await get(`comp-${id}`, prodCache);
|
comp.pending.delete(id);
|
||||||
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,9 +37,9 @@ export const scanComponent = async (items: IContent[], use_cache?: boolean) => {
|
||||||
comp.pending.delete(id);
|
comp.pending.delete(id);
|
||||||
comp.list[id] = item;
|
comp.list[id] = item;
|
||||||
|
|
||||||
await set(`comp-${id}`, item, prodCache);
|
await set(`comp-${id}`, item);
|
||||||
}
|
}
|
||||||
await scanComponent(Object.values(res), use_cache);
|
await scanComponent(Object.values(res));
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
import { base } from "./base";
|
import { base } from "./base";
|
||||||
import { IRoot } from "../../../utils/types/root";
|
import { IRoot } from "../../../utils/types/root";
|
||||||
import { prodCache } from "./cache";
|
|
||||||
import { get, set } from "idb-keyval";
|
import { get, set } from "idb-keyval";
|
||||||
|
|
||||||
export const loadPage = (page_id: string, use_cache?: boolean) => {
|
export const loadPage = (page_id: string) => {
|
||||||
return new Promise<{
|
return new Promise<{
|
||||||
id: string;
|
id: string;
|
||||||
url: string;
|
url: string;
|
||||||
|
|
@ -11,12 +10,10 @@ export const loadPage = (page_id: string, use_cache?: boolean) => {
|
||||||
}>(async (done) => {
|
}>(async (done) => {
|
||||||
let returned = false;
|
let returned = false;
|
||||||
|
|
||||||
if (use_cache !== false) {
|
const cached = await get(`page-${page_id}`);
|
||||||
const cached = await get(`page-${page_id}`, prodCache);
|
if (cached) {
|
||||||
if (cached) {
|
done(cached);
|
||||||
done(cached);
|
returned = true;
|
||||||
returned = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = (await (
|
const res = (await (
|
||||||
|
|
@ -26,11 +23,6 @@ export const loadPage = (page_id: string, use_cache?: boolean) => {
|
||||||
url: string;
|
url: string;
|
||||||
root: IRoot;
|
root: IRoot;
|
||||||
};
|
};
|
||||||
set(
|
|
||||||
`page-${page_id}`,
|
|
||||||
{ id: page_id, url: res.url, root: res.root },
|
|
||||||
prodCache
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!returned) done(res);
|
if (!returned) done(res);
|
||||||
});
|
});
|
||||||
|
|
@ -48,7 +40,7 @@ export const loadPages = (page_ids: string[]) => {
|
||||||
const ids = [...new Set(page_ids)];
|
const ids = [...new Set(page_ids)];
|
||||||
let is_done = true;
|
let is_done = true;
|
||||||
for (const id of ids) {
|
for (const id of ids) {
|
||||||
const page = await get(`page-${id}`, prodCache);
|
const page = await get(`page-${id}`);
|
||||||
if (page) {
|
if (page) {
|
||||||
result[id] = page;
|
result[id] = page;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -71,10 +63,6 @@ export const loadPages = (page_ids: string[]) => {
|
||||||
root: IRoot;
|
root: IRoot;
|
||||||
}[];
|
}[];
|
||||||
|
|
||||||
for (const [k, v] of Object.entries(res)) {
|
|
||||||
set(`page-${k}`, v, prodCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_done) {
|
if (!is_done) {
|
||||||
done(res);
|
done(res);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import { get, set } from "idb-keyval";
|
|
||||||
import { createRouter } from "radix3";
|
import { createRouter } from "radix3";
|
||||||
import { apiProxy } from "../../../base/load/api/api-proxy";
|
import { apiProxy } from "../../../base/load/api/api-proxy";
|
||||||
import { dbProxy } from "../../../base/load/db/db-proxy";
|
import { dbProxy } from "../../../base/load/db/db-proxy";
|
||||||
|
|
@ -6,7 +5,6 @@ import { IRoot } from "../../../utils/types/root";
|
||||||
import { genMeta } from "../../vi/meta/meta";
|
import { genMeta } from "../../vi/meta/meta";
|
||||||
import { IMeta } from "../../vi/utils/types";
|
import { IMeta } from "../../vi/utils/types";
|
||||||
import { base } from "./base";
|
import { base } from "./base";
|
||||||
import { prodCache } from "./cache";
|
|
||||||
import { scanComponent } from "./component";
|
import { scanComponent } from "./component";
|
||||||
|
|
||||||
const getRoute = () => {
|
const getRoute = () => {
|
||||||
|
|
@ -19,21 +17,15 @@ const getRoute = () => {
|
||||||
layout: any;
|
layout: any;
|
||||||
}>(async (done) => {
|
}>(async (done) => {
|
||||||
let is_done = false;
|
let is_done = false;
|
||||||
const route_cache = await get("route", prodCache);
|
|
||||||
if (route_cache) {
|
|
||||||
done(route_cache);
|
|
||||||
is_done = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
let res = await (await fetch(base.url`_prasi/route`)).json();
|
let res = await (await fetch(base.url`_prasi/route`)).json();
|
||||||
await set("route", res, prodCache);
|
|
||||||
if (!is_done) {
|
if (!is_done) {
|
||||||
done(res);
|
done(res);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initBaseRoute = async (isPreviewProd: boolean) => {
|
export const initBaseRoute = async () => {
|
||||||
const router = createRouter<{ id: string; url: string }>();
|
const router = createRouter<{ id: string; url: string }>();
|
||||||
const pages = [] as { id: string; url: string }[];
|
const pages = [] as { id: string; url: string }[];
|
||||||
try {
|
try {
|
||||||
|
|
@ -45,7 +37,7 @@ export const initBaseRoute = async (isPreviewProd: boolean) => {
|
||||||
base.layout.root = res.layout.root;
|
base.layout.root = res.layout.root;
|
||||||
base.layout.meta = {};
|
base.layout.meta = {};
|
||||||
if (base.layout.root) {
|
if (base.layout.root) {
|
||||||
await scanComponent(base.layout.root.childs, !isPreviewProd);
|
await scanComponent(base.layout.root.childs);
|
||||||
rebuildMeta(base.layout.meta, base.layout.root);
|
rebuildMeta(base.layout.meta, base.layout.root);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ export const Root = () => {
|
||||||
if (base.route.status !== "ready") {
|
if (base.route.status !== "ready") {
|
||||||
if (base.route.status === "init") {
|
if (base.route.status === "init") {
|
||||||
base.route.status = "loading";
|
base.route.status = "loading";
|
||||||
initBaseRoute(isPreviewProd).then(async ({ router, pages }) => {
|
initBaseRoute().then(async ({ router, pages }) => {
|
||||||
detectResponsiveMode();
|
detectResponsiveMode();
|
||||||
base.route.status = "ready";
|
base.route.status = "ready";
|
||||||
base.route.router = router;
|
base.route.router = router;
|
||||||
|
|
@ -97,7 +97,7 @@ export const Root = () => {
|
||||||
const cache = base.page.cache[page.id];
|
const cache = base.page.cache[page.id];
|
||||||
|
|
||||||
if (!cache) {
|
if (!cache) {
|
||||||
loadPage(page.id, !isPreviewProd)
|
loadPage(page.id)
|
||||||
.then(async ({ root }) => {
|
.then(async ({ root }) => {
|
||||||
if (page) {
|
if (page) {
|
||||||
const p = {
|
const p = {
|
||||||
|
|
@ -106,7 +106,7 @@ export const Root = () => {
|
||||||
root,
|
root,
|
||||||
meta: {},
|
meta: {},
|
||||||
};
|
};
|
||||||
await scanComponent(root.childs, !isPreviewProd);
|
await scanComponent(root.childs);
|
||||||
rebuildMeta(p.meta, root);
|
rebuildMeta(p.meta, root);
|
||||||
base.page.cache[p.id] = p;
|
base.page.cache[p.id] = p;
|
||||||
render();
|
render();
|
||||||
|
|
@ -199,7 +199,7 @@ export const Root = () => {
|
||||||
root: page.root,
|
root: page.root,
|
||||||
meta: {},
|
meta: {},
|
||||||
};
|
};
|
||||||
await scanComponent(page.root.childs, !isPreviewProd);
|
await scanComponent(page.root.childs);
|
||||||
rebuildMeta(p.meta, page.root);
|
rebuildMeta(p.meta, page.root);
|
||||||
base.page.cache[p.id] = p;
|
base.page.cache[p.id] = p;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue