This commit is contained in:
Rizky 2024-08-05 22:15:45 +07:00
parent fab8bb24b5
commit 706048c882
4 changed files with 68 additions and 50 deletions

View File

@ -15,7 +15,6 @@ export const _ = {
let is_msgpack = req.query_parameters["msgpack"];
console.log(is_msgpack);
if (validate(site_id)) {
const mode = is_msgpack ? "binary" : "string";
const result = {

File diff suppressed because one or more lines are too long

View File

@ -2,8 +2,19 @@ import { get } from "idb-keyval";
import { IRoot } from "../../../utils/types/root";
import { base } from "./base";
const pendingPage = {} as Record<
string,
Promise<{
id: string;
url: string;
root: IRoot;
}>
>;
export const loadPage = (page_id: string) => {
return new Promise<{
if (typeof pendingPage[page_id] === "object") return pendingPage[page_id];
pendingPage[page_id] = new Promise<{
id: string;
url: string;
root: IRoot;
@ -22,10 +33,18 @@ export const loadPage = (page_id: string) => {
id: string;
url: string;
root: IRoot;
content_tree?: IRoot;
};
if (!res.root && res.content_tree) {
res.root = res.content_tree;
delete res.content_tree;
}
if (!returned) done(res);
});
return pendingPage[page_id];
};
export const loadPages = (page_ids: string[]) => {
@ -48,7 +67,7 @@ export const loadPages = (page_ids: string[]) => {
break;
}
}
if (is_done) {
done(result);
}

View File

@ -7,10 +7,11 @@ import { IMeta } from "../../vi/utils/types";
import { base } from "./base";
import { scanComponent } from "./component";
const cached = { route: null as any };
const cached = { route: null as any, promise: null as any };
const getRoute = () => {
return new Promise<{
if (cached.promise) return cached.promise;
cached.promise = new Promise<{
site: any;
urls: {
id: string;
@ -19,10 +20,9 @@ const getRoute = () => {
layout: any;
}>(async (done) => {
if (cached.route) done(cached.route);
let is_done = false;
let res = await fetch(base.url`_prasi/route`);
let is_done = false;
const res = await fetch(base.url`_prasi/route`);
if (!is_done) {
if (!res.headers.get("content-encoding")) {
fetch(base.url`_prasi/compress/only-gz`);