Skip to content

Commit

Permalink
avoid calculating hash of all index pattern properties (elastic#184292)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar authored and rshen91 committed May 29, 2024
1 parent 6ab42e4 commit d76209c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/plugins/kibana_utils/common/calculate_object_hash.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { calculateObjectHash } from './calculate_object_hash';

describe('calculateObjectHash', () => {
test('calculates hash of the object', () => {
const object = { test: 123 };

expect(calculateObjectHash(object)).toEqual('5094c3dc');
});

test('ignore inner props of index object expect for the value.id', () => {
const object1 = { test: 123, index: { value: { id: 'test', otherprop: 1 } } };
const object2 = { test: 123, index: { value: { id: 'test', otherprop: 2 } } };

expect(calculateObjectHash(object1)).toEqual(calculateObjectHash(object2));
});
});
3 changes: 3 additions & 0 deletions src/plugins/kibana_utils/common/calculate_object_hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ function foldValue(input: number, value: any, key: string, seen: any[]) {
if (key === 'vis' && value.constructor.name === 'Vis') {
return hash;
}
if (key === 'index' && value.value?.id) {
return fold(hash, value.value.id);
}
if (seen.indexOf(value) !== -1) {
return fold(hash, '[Circular]' + key);
}
Expand Down

0 comments on commit d76209c

Please sign in to comment.