Skip to content

Commit b2a4907

Browse files
authored
Update helpers to use new multisearch types (#2697)
* Update helpers to use correct multisearch types The spec combined definitions for search and multisearch bodies in elastic/elasticsearch-specification#2960. * Stop copying project files to Dockerfile Slightly faster run times for codegen, hopefully.
1 parent e8dc747 commit b2a4907

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

.buildkite/Dockerfile

-2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,3 @@ WORKDIR /usr/src/app
1212

1313
COPY package.json .
1414
RUN npm install
15-
16-
COPY . .

.buildkite/Dockerfile-make

-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,3 @@ USER ${BUILDER_UID}:${BUILDER_GID}
2525
# install dependencies
2626
COPY package.json .
2727
RUN npm install
28-
29-
# copy project files
30-
COPY . .

src/helpers.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface MsearchHelperOptions extends T.MsearchRequest {
4141

4242
export interface MsearchHelper extends Promise<void> {
4343
stop: (error?: Error | null) => void
44-
search: <TDocument = unknown>(header: T.MsearchMultisearchHeader, body: T.MsearchMultisearchBody) => Promise<MsearchHelperResponse<TDocument>>
44+
search: <TDocument = unknown>(header: T.MsearchMultisearchHeader, body: T.SearchSearchRequestBody) => Promise<MsearchHelperResponse<TDocument>>
4545
}
4646

4747
export interface MsearchHelperResponse<TDocument> {
@@ -362,7 +362,7 @@ export default class Helpers {
362362
// TODO: support abort a single search?
363363
// NOTE: the validation checks are synchronous and the callback/promise will
364364
// be resolved in the same tick. We might want to fix this in the future.
365-
search<TDocument = unknown> (header: T.MsearchMultisearchHeader, body: T.MsearchMultisearchBody): Promise<MsearchHelperResponse<TDocument>> {
365+
search<TDocument = unknown> (header: T.MsearchMultisearchHeader, body: T.SearchSearchRequestBody): Promise<MsearchHelperResponse<TDocument>> {
366366
if (stopReading) {
367367
const error = stopError === null
368368
? new ConfigurationError('The msearch processor has been stopped')
@@ -397,7 +397,7 @@ export default class Helpers {
397397

398398
async function iterate (): Promise<void> {
399399
const { semaphore, finish } = buildSemaphore()
400-
const msearchBody: Array<T.MsearchMultisearchHeader | T.MsearchMultisearchBody> = []
400+
const msearchBody: Array<T.MsearchMultisearchHeader | T.SearchSearchRequestBody> = []
401401
const callbacks: any[] = []
402402
let loadedOperations = 0
403403
timeoutRef = setTimeout(onFlushTimeout, flushInterval) // eslint-disable-line
@@ -490,7 +490,7 @@ export default class Helpers {
490490
}
491491
}
492492

493-
function send (msearchBody: Array<T.MsearchMultisearchHeader | T.MsearchMultisearchBody>, callbacks: any[]): void {
493+
function send (msearchBody: Array<T.MsearchMultisearchHeader | T.SearchSearchRequestBody>, callbacks: any[]): void {
494494
/* istanbul ignore if */
495495
if (running > concurrency) {
496496
throw new Error('Max concurrency reached')
@@ -508,15 +508,15 @@ export default class Helpers {
508508
}
509509
}
510510

511-
function msearchOperation (msearchBody: Array<T.MsearchMultisearchHeader | T.MsearchMultisearchBody>, callbacks: any[], done: () => void): void {
511+
function msearchOperation (msearchBody: Array<T.MsearchMultisearchHeader | T.SearchSearchRequestBody>, callbacks: any[], done: () => void): void {
512512
let retryCount = retries
513513

514514
// Instead of going full on async-await, which would make the code easier to read,
515515
// we have decided to use callback style instead.
516516
// This because every time we use async await, V8 will create multiple promises
517517
// behind the scenes, making the code slightly slower.
518518
tryMsearch(msearchBody, callbacks, retrySearch)
519-
function retrySearch (msearchBody: Array<T.MsearchMultisearchHeader | T.MsearchMultisearchBody>, callbacks: any[]): void {
519+
function retrySearch (msearchBody: Array<T.MsearchMultisearchHeader | T.SearchSearchRequestBody>, callbacks: any[]): void {
520520
if (msearchBody.length > 0 && retryCount > 0) {
521521
retryCount -= 1
522522
setTimeout(tryMsearch, wait, msearchBody, callbacks, retrySearch)
@@ -528,7 +528,7 @@ export default class Helpers {
528528

529529
// This function never returns an error, if the msearch operation fails,
530530
// the error is dispatched to all search executors.
531-
function tryMsearch (msearchBody: Array<T.MsearchMultisearchHeader | T.MsearchMultisearchBody>, callbacks: any[], done: (msearchBody: Array<T.MsearchMultisearchHeader | T.MsearchMultisearchBody>, callbacks: any[]) => void): void {
531+
function tryMsearch (msearchBody: Array<T.MsearchMultisearchHeader | T.SearchSearchRequestBody>, callbacks: any[], done: (msearchBody: Array<T.MsearchMultisearchHeader | T.SearchSearchRequestBody>, callbacks: any[]) => void): void {
532532
client.msearch(Object.assign({}, msearchOptions, { body: msearchBody }), reqOptions as TransportRequestOptionsWithMeta)
533533
.then(results => {
534534
const retryBody = []

0 commit comments

Comments
 (0)