From 1e2fce7483bd7bd90a8a6f534bffa731448d02d9 Mon Sep 17 00:00:00 2001 From: Beau Cameron Date: Mon, 5 Feb 2024 09:20:05 -0700 Subject: [PATCH] Reverting Batching/Caching Changes Revert caching and rawData changes. --- docs/queryable/behaviors.md | 15 ++++++--------- packages/queryable/behaviors/caching.ts | 11 ++++------- packages/queryable/behaviors/parsers.ts | 7 +------ packages/queryable/queryable.ts | 3 +-- 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/docs/queryable/behaviors.md b/docs/queryable/behaviors.md index b7fb91964..5bc94e91f 100644 --- a/docs/queryable/behaviors.md +++ b/docs/queryable/behaviors.md @@ -176,19 +176,16 @@ export function Caching(props?: ICachingProps): TimelinePipe { const cached = getCachedValue(); // we need to ensure that result stays "undefined" unless we mean to set null as the result - if (cached === null) { + if (cached === null) { // if we don't have a cached result we need to get it after the request is sent. Get the raw value (un-parsed) to store into cache - this.on.rawData(noInherit(async function (response) { - setCachedValue(response); - })); + this.on.post(async function (url: URL, result: any) { + setCachedValue(result); + return [url, result]; + }); } else { - // if we find it in cache, override send request, and continue flow through timeline and parsers. - this.on.auth.clear(); - this.on.send.replace(async function (this: Queryable) { - return new Response(cached, {}); - }); + result = cached; } } diff --git a/packages/queryable/behaviors/caching.ts b/packages/queryable/behaviors/caching.ts index c88d402b4..f1dad8446 100644 --- a/packages/queryable/behaviors/caching.ts +++ b/packages/queryable/behaviors/caching.ts @@ -97,16 +97,13 @@ export function Caching(props?: ICachingProps): TimelinePipe { if (cached === null) { // if we don't have a cached result we need to get it after the request is sent. Get the raw value (un-parsed) to store into cache - instance.on.rawData(noInherit(async function (response) { - setCachedValue(response); + this.on.post(noInherit(async function (url: URL, result: any) { + setCachedValue(result); + return [url, result]; })); } else { - // if we find it in cache, override send request, and continue flow through timeline and parsers. - this.on.auth.clear(); - this.on.send.replace(async function (this: Queryable) { - return new Response(cached, {}); - }); + result = cached; } } diff --git a/packages/queryable/behaviors/parsers.ts b/packages/queryable/behaviors/parsers.ts index 753a5dd74..68b171310 100644 --- a/packages/queryable/behaviors/parsers.ts +++ b/packages/queryable/behaviors/parsers.ts @@ -108,12 +108,7 @@ export function parseBinderWithErrorCheck(impl: (r: Response) => Promise): instance.on.parse(async (url: URL, response: Response, result: any): Promise<[URL, Response, any]> => { if (response.ok && typeof result === "undefined") { - const respClone = response.clone(); - - // https://github.com/node-fetch/node-fetch?tab=readme-ov-file#custom-highwatermark - const [implResult, raw] = await Promise.all([impl(response), respClone.text()]); - result = implResult; - (instance).emit.rawData(raw); + result = await impl(response); } return [url, response, result]; diff --git a/packages/queryable/queryable.ts b/packages/queryable/queryable.ts index b1db19f6f..3b5baaebb 100644 --- a/packages/queryable/queryable.ts +++ b/packages/queryable/queryable.ts @@ -24,8 +24,7 @@ const DefaultMoments = { send: request(), parse: asyncReduce(), post: asyncReduce(), - data: broadcast(), - rawData: broadcast(), + data: broadcast() } as const; export type QueryableInit = Queryable | string | [Queryable, string];