mirror of
https://github.com/elastic/kibana.git
synced 2025-06-28 03:01:21 -04:00
freeze response (#222160)
This commit is contained in:
parent
10cc7b3c62
commit
180f90a65c
8 changed files with 20 additions and 13 deletions
|
@ -109,7 +109,7 @@ export class SearchAPI {
|
|||
),
|
||||
map((data) => ({
|
||||
name: requestId,
|
||||
rawResponse: data.rawResponse,
|
||||
rawResponse: structuredClone(data.rawResponse),
|
||||
}))
|
||||
)
|
||||
)
|
||||
|
|
|
@ -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';
|
||||
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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 { estypes } from '@elastic/elasticsearch';
|
||||
import {
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -64,6 +64,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 {
|
||||
EVENT_TYPE_DATA_SEARCH_TIMEOUT,
|
||||
EVENT_PROPERTY_SEARCH_TIMEOUT_MS,
|
||||
|
@ -623,6 +624,8 @@ export class SearchInterceptor {
|
|||
) {
|
||||
this.showRestoreWarning(sessionId);
|
||||
}
|
||||
|
||||
defaultFreeze(response);
|
||||
}),
|
||||
finalize(() => {
|
||||
this.pendingCount$.next(this.pendingCount$.getValue() - 1);
|
||||
|
|
|
@ -38,6 +38,7 @@ export {
|
|||
useContainerSelector,
|
||||
useContainerState,
|
||||
createStateContainer,
|
||||
defaultFreeze,
|
||||
} from './state_containers';
|
||||
export type { KibanaServerError } from './errors';
|
||||
export {
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue