This commit is contained in:
Rizky 2024-07-02 08:45:07 +07:00
parent 9e239c1d78
commit 398f9e6926
2 changed files with 11 additions and 3 deletions

View File

@ -12,6 +12,7 @@ import { g } from "utils/global";
import brotliPromise from "brotli-wasm";
import mime from "mime";
const encoder = new TextEncoder();
export const _ = {
url: "/prod/:site_id/**",
async api() {
@ -255,10 +256,15 @@ export const _ = {
g.br = await brotliPromise;
}
setTimeout(() => {
g.route_cache[site_id] = g.br.compress(res);
if (!g.route_cache_compressing)
g.route_cache_compressing = new Set();
if (g.route_cache_compressing.has(site_id)) return;
g.route_cache_compressing.add(site_id);
g.route_cache[site_id] = g.br.compress(encoder.encode(res));
g.route_cache_compressing.delete(site_id);
}, 100);
return new Response(res, {
return new Response(await gzipAsync(res), {
headers: {
"content-type": "application/json",
"content-encoding": "gzip",

View File

@ -11,6 +11,7 @@ import {
apiProxy,
} from "../../../app/web/src/base/load/api/api-proxy";
import { dbProxy } from "../../../app/web/src/base/load/db/db-proxy";
import { BrotliWasmType } from "brotli-wasm";
type SingleRoute = {
url: string;
@ -59,11 +60,12 @@ export const g = global as unknown as {
Y: typeof Y;
syncronize: typeof syncronize;
static_cache: any;
route_cache_compressing: Set<string>;
route_cache: Record<string, any>;
code_index_compressing: Set<string>;
code_index_cache: Record<
string,
Record<string, { ts: number; content: any;type: string; }>
>;
br: any
br: BrotliWasmType
};