fix
This commit is contained in:
parent
9e239c1d78
commit
398f9e6926
|
|
@ -12,6 +12,7 @@ import { g } from "utils/global";
|
||||||
import brotliPromise from "brotli-wasm";
|
import brotliPromise from "brotli-wasm";
|
||||||
import mime from "mime";
|
import mime from "mime";
|
||||||
|
|
||||||
|
const encoder = new TextEncoder();
|
||||||
export const _ = {
|
export const _ = {
|
||||||
url: "/prod/:site_id/**",
|
url: "/prod/:site_id/**",
|
||||||
async api() {
|
async api() {
|
||||||
|
|
@ -255,10 +256,15 @@ export const _ = {
|
||||||
g.br = await brotliPromise;
|
g.br = await brotliPromise;
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
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);
|
}, 100);
|
||||||
|
|
||||||
return new Response(res, {
|
return new Response(await gzipAsync(res), {
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
"content-encoding": "gzip",
|
"content-encoding": "gzip",
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import {
|
||||||
apiProxy,
|
apiProxy,
|
||||||
} from "../../../app/web/src/base/load/api/api-proxy";
|
} from "../../../app/web/src/base/load/api/api-proxy";
|
||||||
import { dbProxy } from "../../../app/web/src/base/load/db/db-proxy";
|
import { dbProxy } from "../../../app/web/src/base/load/db/db-proxy";
|
||||||
|
import { BrotliWasmType } from "brotli-wasm";
|
||||||
|
|
||||||
type SingleRoute = {
|
type SingleRoute = {
|
||||||
url: string;
|
url: string;
|
||||||
|
|
@ -59,11 +60,12 @@ export const g = global as unknown as {
|
||||||
Y: typeof Y;
|
Y: typeof Y;
|
||||||
syncronize: typeof syncronize;
|
syncronize: typeof syncronize;
|
||||||
static_cache: any;
|
static_cache: any;
|
||||||
|
route_cache_compressing: Set<string>;
|
||||||
route_cache: Record<string, any>;
|
route_cache: Record<string, any>;
|
||||||
code_index_compressing: Set<string>;
|
code_index_compressing: Set<string>;
|
||||||
code_index_cache: Record<
|
code_index_cache: Record<
|
||||||
string,
|
string,
|
||||||
Record<string, { ts: number; content: any;type: string; }>
|
Record<string, { ts: number; content: any;type: string; }>
|
||||||
>;
|
>;
|
||||||
br: any
|
br: BrotliWasmType
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue