Skip to content

Commit 87299e5

Browse files
committed
fix: reduce strict caching for module packages
Signed-off-by: Okiki <[email protected]>
1 parent 304c922 commit 87299e5

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/edge/mod.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import JSON5 from "./vendor/json5.ts";
55

66
// @deno-types="https://deno.land/x/upstash_redis/pkg/redis.ts"
77
import { Redis } from "@upstash/redis";
8-
import { dirname, fromFileUrl, join, extname, basename } from "@std/path";
8+
import { dirname, fromFileUrl, join, extname, basename } from "@std/path/posix";
99

1010
import { decodeBase64 } from "@std/encoding/base64";
1111

@@ -291,6 +291,9 @@ export default {
291291
initialValue: initialValue.trim(),
292292
});
293293
const jsonKey = `json/${JSON5.stringify(jsonKeyObj).trim()}`;
294+
console.log({
295+
jsonKey
296+
})
294297

295298
const badgeResult = url.searchParams.get("badge");
296299
const badgeStyle = url.searchParams.get("badge-style");
@@ -379,11 +382,12 @@ export default {
379382
} else if (modules.length === 1 && exportAll && !mutationQueries) {
380383
const [moduleName, mode] = modules[0];
381384
if (mode === "export") {
382-
const PackageResultString = await redis.get<string>(getPackageResultKey(moduleName));
385+
const PackageResultKey = getPackageResultKey(moduleName) + "/" + jsonKey;
386+
const PackageResultString = await redis.get<string>(PackageResultKey);
383387
const PackageResult = PackageResultString ? JSON5.parse<BundleResult>(PackageResultString) : null;
384388
const fileQuery = fileCheck ? PackageResult?.fileId : true;
385389
if (PackageResult && fileQuery) {
386-
console.log("Respond with Module Response from Permanent Cache", getPackageResultKey(moduleName))
390+
console.log("Respond with Module Response from Permanent Cache", getPackageResultKey(moduleName), PackageResultKey)
387391
return await generateResult([badgeKey, badgeID], [PackageResult, undefined], url, true, Date.now() - start, redis);
388392
}
389393
}
@@ -441,10 +445,10 @@ export default {
441445
console.log("Respond with New Bundle Result")
442446
return await generateResult([badgeKey, badgeID], [value, resultText], url, false, Date.now() - start, redis);
443447
} catch (e) {
444-
if ("msgs" in e && e.msgs) {
448+
if ("msgs" in (e as Error) && (e as Record<PropertyKey, unknown>).msgs) {
445449
try {
446450
return new Response(
447-
generateHTMLMessages(e.msgs as string[]),
451+
generateHTMLMessages((e as Record<PropertyKey, unknown>).msgs as string[]),
448452
{
449453
status: 404,
450454
headers: [
@@ -460,7 +464,7 @@ export default {
460464
console.error(e)
461465

462466
return new Response(
463-
JSON.stringify({ error: e.toString() }),
467+
JSON.stringify({ error: (e as Error).toString() }),
464468
{ status: 400, }
465469
)
466470
}

0 commit comments

Comments
 (0)