Skip to content

Commit

Permalink
Reverting Batching/Caching Changes
Browse files Browse the repository at this point in the history
Revert caching and rawData changes.
  • Loading branch information
bcameron1231 committed Feb 5, 2024
1 parent f5e71dd commit 1e2fce7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 24 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
3 changes: 1 addition & 2 deletions packages/queryable/queryable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ const DefaultMoments = {
send: request<QueryableSendObserver>(),
parse: asyncReduce<QueryableParseObserver>(),
post: asyncReduce<QueryablePostObserver>(),
data: broadcast<QueryableDataObserver>(),
rawData: broadcast<QueryableDataObserver>(),
data: broadcast<QueryableDataObserver>()

Check failure on line 27 in packages/queryable/queryable.ts

View workflow job for this annotation

GitHub Actions / run_pr_tests

Missing trailing comma
} as const;

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

0 comments on commit 1e2fce7

Please sign in to comment.