Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverting Batching/Caching Changes #2929

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading