Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class SearchAPI {
),
map((data) => ({
name: requestId,
rawResponse: data.rawResponse,
rawResponse: structuredClone(data.rawResponse),
}))
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import moment from 'moment-timezone';
import _, { cloneDeep } from 'lodash';
import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import type { Assign } from '@kbn/utility-types';
import { isRangeFilter, TimeRange, RangeFilter } from '@kbn/es-query';
Expand Down Expand Up @@ -472,9 +472,8 @@ export class AggConfigs {
if (!this.hasTimeShifts()) {
return response;
}
let transformedRawResponse = response.rawResponse;
const transformedRawResponse = structuredClone(response.rawResponse);
if (!response.rawResponse.aggregations) {
transformedRawResponse = cloneDeep(response.rawResponse);
transformedRawResponse.aggregations = {
doc_count: response.rawResponse.hits?.total as estypes.AggregationsAggregate,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { isNumber, keys, values, find, each, cloneDeep, flatten } from 'lodash';
import { isNumber, keys, values, find, each, flatten } from 'lodash';
import { i18n } from '@kbn/i18n';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import {
Expand Down Expand Up @@ -227,7 +227,7 @@ export const buildOtherBucketAgg = (
bucket,
isNumber(bucketObjKey) ? undefined : bucketObjKey
);
const filter = cloneDeep(bucket.filters) || currentAgg.createFilter(bucketKey);
const filter = structuredClone(bucket.filters) || currentAgg.createFilter(bucketKey);
const newFilters = flatten([...filters, filter]);
walkBucketTree(
newAggIndex,
Expand Down Expand Up @@ -306,8 +306,12 @@ export const mergeOtherBucketAggResponse = (
requestAgg: Record<string, any>,
otherFilterBuilder: (requestAgg: Record<string, any>, key: string, otherAgg: IAggConfig) => Filter
): estypes.SearchResponse<any> => {
const updatedResponse = cloneDeep(response);
const aggregationsRoot = getCorrectAggregationsCursorFromResponse(otherResponse, aggsConfig);
const updatedResponse = structuredClone(response);
const updatedOtherResponse = structuredClone(otherResponse);
const aggregationsRoot = getCorrectAggregationsCursorFromResponse(
updatedOtherResponse,
aggsConfig
);
const updatedAggregationsRoot = getCorrectAggregationsCursorFromResponse(
updatedResponse,
aggsConfig
Expand Down Expand Up @@ -349,7 +353,7 @@ export const updateMissingBucket = (
aggConfigs: IAggConfigs,
agg: IAggConfig
) => {
const updatedResponse = cloneDeep(response);
const updatedResponse = structuredClone(response);
const aggResultBuckets = getAggConfigResultMissingBuckets(
getCorrectAggregationsCursorFromResponse(updatedResponse, aggConfigs),
agg.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import type {
} from '@kbn/search-types';
import { createEsError, isEsError, renderSearchError } from '@kbn/search-errors';
import type { IKibanaSearchResponse, ISearchOptions } from '@kbn/search-types';
import { defaultFreeze } from '@kbn/kibana-utils-plugin/common';
import {
AsyncSearchGetResponse,
ErrorResponseBase,
Expand Down Expand Up @@ -653,6 +654,8 @@ export class SearchInterceptor {
) {
this.showRestoreWarning(sessionId);
}

defaultFreeze(response);
}),
finalize(() => {
this.pendingCount$.next(this.pendingCount$.getValue() - 1);
Expand Down
1 change: 1 addition & 0 deletions src/platform/plugins/shared/kibana_utils/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export {
useContainerSelector,
useContainerState,
createStateContainer,
defaultFreeze,
} from './state_containers';
export type { KibanaServerError } from './errors';
export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const isProduction =
? process.env.NODE_ENV === 'production'
: !process.env.NODE_ENV || process.env.NODE_ENV === 'production';

const defaultFreeze: <T>(value: T) => T = isProduction
export const defaultFreeze: <T>(value: T) => T = isProduction
? <T>(value: T) => value as T
: <T>(value: T): T => {
const isFreezable = value !== null && typeof value === 'object';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type {

export type { CreateStateContainerOptions } from './create_state_container';

export { createStateContainer } from './create_state_container';
export { createStateContainer, defaultFreeze } from './create_state_container';

export {
createStateContainerReactHelpers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export class ESSearchSource extends AbstractESSource implements IMvtVectorSource
entityBuckets.forEach((entityBucket: any) => {
const hits = _.get(entityBucket, 'entityHits.hits.hits', []);
// Reverse hits list so top documents by sort are drawn on top
allHits.push(...hits.reverse());
allHits.push(...hits.slice().reverse());
if (isTotalHitsGreaterThan(entityBucket.entityHits.hits.total, hits.length)) {
areTopHitsTrimmed = true;
}
Expand Down Expand Up @@ -489,7 +489,7 @@ export class ESSearchSource extends AbstractESSource implements IMvtVectorSource
const isTimeExtentForTimeslice =
requestMeta.timeslice !== undefined && !useRequestMetaWithoutTimeslice;
return {
hits: resp.hits.hits.reverse(), // Reverse hits so top documents by sort are drawn on top
hits: resp.hits.hits.slice().reverse(), // Reverse hits so top documents by sort are drawn on top
meta: {
resultsCount: resp.hits.hits.length,
areResultsTrimmed: isTotalHitsGreaterThan(resp.hits.total, resp.hits.hits.length),
Expand Down