-
Notifications
You must be signed in to change notification settings - Fork 28
middleware poc with compression middleware #306
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
base: 9.3.0-unstable.20251003
Are you sure you want to change the base?
Conversation
"./lib/pool/WeightedConnectionPool": "./lib/pool/WeightedConnectionPool.js" | ||
"./lib/pool/WeightedConnectionPool": "./lib/pool/WeightedConnectionPool.js", | ||
"./middleware": "./lib/middleware/index.js", | ||
"./lib/middleware": "./lib/middleware/index.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oof, reminder that I want to refactor both libraries to properly support ESM. this pattern was a naive attempt to move that direction, but I'm almost certain there was a simpler way. 🙃
onBeforeRequest = async (ctx: MiddlewareContext): Promise<MiddlewareResult | undefined> => { | ||
if (!this.shouldCompress(ctx)) { | ||
return undefined // void = no changes needed | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onBeforeRequest = async (ctx: MiddlewareContext): Promise<MiddlewareResult | undefined> => { | |
if (!this.shouldCompress(ctx)) { | |
return undefined // void = no changes needed | |
} | |
onBeforeRequest = async (ctx: MiddlewareContext): Promise<MiddlewareResult | void> => { | |
if (!this.shouldCompress(ctx)) { | |
return // void = no changes needed | |
} |
void
is a little clearer than undefined
, IMO.
return { | ||
...current, | ||
|
||
// Merge request object if provided | ||
request: updates.request != null | ||
? { | ||
...current.request, | ||
...updates.request, | ||
headers: updates.request.headers != null | ||
? { | ||
...current.request.headers, | ||
...updates.request.headers | ||
} | ||
: current.request.headers | ||
} | ||
: current.request, | ||
|
||
// Replace shared map if provided (maps are immutable) | ||
shared: updates.shared ?? current.shared | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the bit we were worried would be a perf issue: deep-merging objects on a very hot code path could lead to a lot more garbage collection, which is a CPU hog.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tried sth out here with benchmarked comparison b/w original code - original deep merge - optimized deep merge
Next steps:
@elastic/transport
with middleware exportselasticsearch-js
to validate client integrationExample client usage: