Skip to content

Commit 3d7abe3

Browse files
Replace JSON.stringify based object comparisions with lodash.isEqual (#943)
## Changes <!-- Summary of your changes that are easy to understand --> ## Tests <!-- How is this tested? -->
1 parent 29474b3 commit 3d7abe3

File tree

5 files changed

+9
-8
lines changed

5 files changed

+9
-8
lines changed

packages/databricks-vscode/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@
704704
"add": "^2.0.6",
705705
"ansi-to-html": "^0.7.2",
706706
"bcryptjs": "^2.4.3",
707+
"lodash": "^4.17.21",
707708
"triple-beam": "^1.4.1",
708709
"winston": "^3.10.0",
709710
"yaml": "^2.3.2"

packages/databricks-vscode/src/cluster/ClusterManager.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {compute, Time, TimeUnits} from "@databricks/databricks-sdk";
22
import {Cluster} from "../sdk-extensions";
33
import {CancellationTokenSource, Disposable} from "vscode";
4-
4+
import _ from "lodash";
55
export class ClusterManager implements Disposable {
66
private cancellationTokenSource?: CancellationTokenSource;
77
private refreshTimer?: NodeJS.Timer;
@@ -18,9 +18,7 @@ export class ClusterManager implements Disposable {
1818
this.refreshTimer = setInterval(async () => {
1919
const oldState = this.cluster.state;
2020
await this.cluster.refresh();
21-
if (
22-
JSON.stringify(oldState) !== JSON.stringify(this.cluster.state)
23-
) {
21+
if (!_.isEqual(oldState, this.cluster.state)) {
2422
this.onChange(this.cluster.state);
2523
}
2624
}, this.refreshTimeout.toMillSeconds().value);

packages/databricks-vscode/src/configuration/BundleConfigReaderWriter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {BundleFileSet, parseBundleYaml, writeBundleYaml} from "../bundle";
33
import {BundleTarget} from "../bundle/types";
44
import {Mutex} from "../locking";
55
import {BundleConfig, ConfigReaderWriter, isBundleConfigKey} from "./types";
6-
6+
import _ from "lodash";
77
/**
88
* Reads and writes bundle configs. This class does not notify when the configs change.
99
* We use the BundleWatcher to notify when the configs change.
@@ -178,7 +178,8 @@ export class BundleConfigReaderWriter
178178
}
179179

180180
const newTargetData = this.writerMapping[key](targetData, value);
181-
if (JSON.stringify(newTargetData) === JSON.stringify(targetData)) {
181+
182+
if (_.isEqual(newTargetData, targetData)) {
182183
return;
183184
}
184185
data.targets = {...data.targets, [target]: newTargetData};

packages/databricks-vscode/src/configuration/ConfigModel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {Mutex} from "../locking";
1313
import {BundleWatcher} from "../bundle";
1414
import {CachedValue} from "../locking/CachedValue";
1515
import {StateStorage} from "../vscode-objs/StateStorage";
16+
import _ from "lodash";
1617

1718
function isDirectToBundleConfig(
1819
key: keyof BundleConfig,
@@ -72,8 +73,7 @@ export class ConfigModel implements Disposable {
7273
(oldValue === null && newValue[key] !== undefined) ||
7374
// Old value is not null, and old and new values for the key are different
7475
(oldValue !== null &&
75-
JSON.stringify(oldValue.config[key]) !==
76-
JSON.stringify(newValue[key]))
76+
!_.isEqual(oldValue.config[key], newValue[key]))
7777
) {
7878
this.changeEmitters.get(key)?.emitter.fire();
7979
didAnyConfigChange = true;

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3910,6 +3910,7 @@ __metadata:
39103910
fs-extra: ^11.1.1
39113911
glob: ^10.3.10
39123912
json-schema-to-typescript: ^13.1.1
3913+
lodash: ^4.17.21
39133914
mocha: ^10.2.0
39143915
mock-require: ^3.0.3
39153916
nyc: ^15.1.0

0 commit comments

Comments
 (0)