fix
This commit is contained in:
parent
2469b692b6
commit
f64191a2c1
File diff suppressed because one or more lines are too long
|
|
@ -1,6 +1,7 @@
|
||||||
import hash_sum from "hash-sum";
|
import hash_sum from "hash-sum";
|
||||||
import pako from "pako";
|
import pako from "pako";
|
||||||
import { fetchViaProxy } from "../proxy";
|
import { fetchViaProxy } from "../proxy";
|
||||||
|
import { del, get, set } from "idb-keyval";
|
||||||
|
|
||||||
const schema_promise = {
|
const schema_promise = {
|
||||||
tables: {} as Record<string, any>,
|
tables: {} as Record<string, any>,
|
||||||
|
|
@ -138,10 +139,7 @@ export const dbProxy = (dburl: string) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const cachedQueryResult: Record<
|
const editorQueryLoaded: Record<string, true> = {};
|
||||||
string,
|
|
||||||
{ timestamp: number; result: any; promise: Promise<any> }
|
|
||||||
> = {};
|
|
||||||
|
|
||||||
export const fetchSendDb = async (params: any, dburl: string) => {
|
export const fetchSendDb = async (params: any, dburl: string) => {
|
||||||
const base = new URL(dburl);
|
const base = new URL(dburl);
|
||||||
|
|
@ -156,55 +154,49 @@ export const fetchSendDb = async (params: any, dburl: string) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const hsum = hash_sum(params);
|
const hsum = hash_sum(params);
|
||||||
let cached = cachedQueryResult[hsum];
|
|
||||||
|
|
||||||
if (!cached || (cached && Date.now() - cached.timestamp > 1000)) {
|
let isEditor = false;
|
||||||
cachedQueryResult[hsum] = {
|
if (
|
||||||
timestamp: Date.now(),
|
base.hostname !== location.hostname &&
|
||||||
promise: fetchViaProxy(
|
(window as any).isEditor &&
|
||||||
url,
|
["prasi.avolut.com", "localhost:4550"].includes(location.host)
|
||||||
params,
|
)
|
||||||
{
|
isEditor = true;
|
||||||
"content-type": "application/json",
|
|
||||||
},
|
const load = async () => {
|
||||||
false
|
const result = await fetchViaProxy(
|
||||||
),
|
url,
|
||||||
result: null,
|
params,
|
||||||
};
|
{
|
||||||
|
"content-type": "application/json",
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
let result = await cachedQueryResult[hsum].promise;
|
|
||||||
cached = cachedQueryResult[hsum];
|
|
||||||
try {
|
try {
|
||||||
if (typeof result === "string") {
|
if (typeof result === "string") return JSON.parse(result);
|
||||||
result = JSON.parse(result);
|
|
||||||
cachedQueryResult[hsum].result = result;
|
|
||||||
return result;
|
|
||||||
} else {
|
|
||||||
cachedQueryResult[hsum].result = result;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (result) {
|
return result;
|
||||||
throw new Error("DBQuery failed:\n" + result);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isEditor) {
|
||||||
|
let result = await get(`editor-db-cache-${hsum}`);
|
||||||
|
if (!result) {
|
||||||
|
result = await load();
|
||||||
|
editorQueryLoaded[hsum] = true;
|
||||||
|
set(`editor-db-cache-${hsum}`, result);
|
||||||
|
} else {
|
||||||
|
if (!editorQueryLoaded[hsum]) {
|
||||||
|
load().then((result) => {
|
||||||
|
set(`editor-db-cache-${hsum}`, result);
|
||||||
|
});
|
||||||
|
editorQueryLoaded[hsum] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cached.result) return cached.result;
|
return await load();
|
||||||
|
|
||||||
let result = await cached.promise;
|
|
||||||
if (result) {
|
|
||||||
try {
|
|
||||||
if (typeof result === "string") {
|
|
||||||
result = JSON.parse(result);
|
|
||||||
return result;
|
|
||||||
} else {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error("DBQuery failed:", result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import type { Monaco, OnMount } from "@monaco-editor/react";
|
import type { Monaco, OnMount } from "@monaco-editor/react";
|
||||||
import { createStore } from "idb-keyval";
|
|
||||||
import trim from "lodash.trim";
|
import trim from "lodash.trim";
|
||||||
import { FC, useEffect } from "react";
|
import { FC, useEffect } from "react";
|
||||||
import { useGlobal, useLocal } from "web-utils";
|
import { useGlobal, useLocal } from "web-utils";
|
||||||
|
|
@ -43,7 +42,6 @@ export const EdScriptMonaco: FC<{}> = () => {
|
||||||
mode: "",
|
mode: "",
|
||||||
imports: "",
|
imports: "",
|
||||||
active_id: "",
|
active_id: "",
|
||||||
idbstore: createStore(`prasi-page-${p.page.cur.id}`, "script-history"),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const Editor = jscript.editor;
|
const Editor = jscript.editor;
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,6 @@ export const ${k} = null as unknown as ${vval};
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(tree_types, tree_usage);
|
|
||||||
register(monaco, tree_types.join("\n"), "typings:tree_types.d.ts");
|
register(monaco, tree_types.join("\n"), "typings:tree_types.d.ts");
|
||||||
register(
|
register(
|
||||||
monaco,
|
monaco,
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,9 @@ export const createViLocal = (
|
||||||
const [_, set] = useState({});
|
const [_, set] = useState({});
|
||||||
const local = ref.current;
|
const local = ref.current;
|
||||||
local.render = () => {
|
local.render = () => {
|
||||||
if ((window as any).prasiContext.render) {
|
const w = window as any;
|
||||||
(window as any).prasiContext.render();
|
if (!w.isEditor && w.prasiContext.render) {
|
||||||
|
w.prasiContext.render();
|
||||||
} else {
|
} else {
|
||||||
set({});
|
set({});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue