Skip to content

Commit

Permalink
Merge pull request #2929 from bcameron1231/revert-caching
Browse files Browse the repository at this point in the history
Reverting Batching/Caching Changes
  • Loading branch information
juliemturner committed Feb 7, 2024
2 parents ab4a5d0 + 45fd918 commit 227bc1a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 23 deletions.
15 changes: 6 additions & 9 deletions docs/queryable/behaviors.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,16 @@ export function Caching(props?: ICachingProps): TimelinePipe<Queryable> {
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;
}
}

Expand Down
11 changes: 4 additions & 7 deletions packages/queryable/behaviors/caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,13 @@ export function Caching(props?: ICachingProps): TimelinePipe<Queryable> {
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;
}
}

Expand Down
7 changes: 1 addition & 6 deletions packages/queryable/behaviors/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,7 @@ export function parseBinderWithErrorCheck(impl: (r: Response) => Promise<any>):
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;
(<any>instance).emit.rawData(raw);
result = await impl(response);
}

return [url, response, result];
Expand Down
1 change: 0 additions & 1 deletion packages/queryable/queryable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const DefaultMoments = {
parse: asyncReduce<QueryableParseObserver>(),
post: asyncReduce<QueryablePostObserver>(),
data: broadcast<QueryableDataObserver>(),
rawData: broadcast<QueryableDataObserver>(),
} as const;

export type QueryableInit = Queryable<any> | string | [Queryable<any>, string];
Expand Down

0 comments on commit 227bc1a

Please sign in to comment.