Resolve port-data-source functions directly instead of writing them to cache.

This commit is contained in:
Dillon Kearns 2023-01-08 10:29:09 -08:00
parent e0d949c008
commit 91d009e70d

View File

@ -53,11 +53,6 @@ function lookupOrPerform(portsFile, mode, rawRequest, hasFsAccess, useCache) {
const portsHash = (portsFile && portsFile.match(/-([^-]+)\.js$/)[1]) || "";
const responsePath = fullPath(portsHash, request, hasFsAccess);
// TODO check cache expiration time and delete and go to else if expired
if (useCache && (await checkFileExists(fs, responsePath))) {
// console.log("Skipping request, found file.");
resolve({ kind: "cache-response-path", value: responsePath });
} else {
let portBackendTask = {};
let portBackendTaskImportError = null;
try {
@ -113,14 +108,9 @@ function lookupOrPerform(portsFile, mode, rawRequest, hasFsAccess, useCache) {
});
} else {
try {
const portFunctionResult = await portBackendTask[portName](input);
await fs.promises.writeFile(
responsePath,
JSON.stringify(jsonResponse(portFunctionResult))
);
resolve({
kind: "cache-response-path",
value: responsePath,
kind: "response-json",
value: jsonResponse(await portBackendTask[portName](input)),
});
} catch (portCallError) {
resolve({
@ -206,14 +196,11 @@ function lookupOrPerform(portsFile, mode, rawRequest, hasFsAccess, useCache) {
console.trace("@@@ request-cache2 HTTP error", error);
reject({
title: "BackendTask.Http Error",
message: `${kleur
.yellow()
.underline(request.url)} ${error.toString()}
message: `${kleur.yellow().underline(request.url)} ${error.toString()}
`,
});
}
}
}
});
}