Skip to content

Commit

Permalink
Replace JSON.stringify based object comparisions with `lodash.isEqu…
Browse files Browse the repository at this point in the history
…al` (#943)

## Changes
<!-- Summary of your changes that are easy to understand -->

## Tests
<!-- How is this tested? -->
  • Loading branch information
kartikgupta-db authored Nov 21, 2023
1 parent 29474b3 commit 3d7abe3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/databricks-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@
"add": "^2.0.6",
"ansi-to-html": "^0.7.2",
"bcryptjs": "^2.4.3",
"lodash": "^4.17.21",
"triple-beam": "^1.4.1",
"winston": "^3.10.0",
"yaml": "^2.3.2"
Expand Down
6 changes: 2 additions & 4 deletions packages/databricks-vscode/src/cluster/ClusterManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {compute, Time, TimeUnits} from "@databricks/databricks-sdk";
import {Cluster} from "../sdk-extensions";
import {CancellationTokenSource, Disposable} from "vscode";

import _ from "lodash";
export class ClusterManager implements Disposable {
private cancellationTokenSource?: CancellationTokenSource;
private refreshTimer?: NodeJS.Timer;
Expand All @@ -18,9 +18,7 @@ export class ClusterManager implements Disposable {
this.refreshTimer = setInterval(async () => {
const oldState = this.cluster.state;
await this.cluster.refresh();
if (
JSON.stringify(oldState) !== JSON.stringify(this.cluster.state)
) {
if (!_.isEqual(oldState, this.cluster.state)) {
this.onChange(this.cluster.state);
}
}, this.refreshTimeout.toMillSeconds().value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {BundleFileSet, parseBundleYaml, writeBundleYaml} from "../bundle";
import {BundleTarget} from "../bundle/types";
import {Mutex} from "../locking";
import {BundleConfig, ConfigReaderWriter, isBundleConfigKey} from "./types";

import _ from "lodash";
/**
* Reads and writes bundle configs. This class does not notify when the configs change.
* We use the BundleWatcher to notify when the configs change.
Expand Down Expand Up @@ -178,7 +178,8 @@ export class BundleConfigReaderWriter
}

const newTargetData = this.writerMapping[key](targetData, value);
if (JSON.stringify(newTargetData) === JSON.stringify(targetData)) {

if (_.isEqual(newTargetData, targetData)) {
return;
}
data.targets = {...data.targets, [target]: newTargetData};
Expand Down
4 changes: 2 additions & 2 deletions packages/databricks-vscode/src/configuration/ConfigModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {Mutex} from "../locking";
import {BundleWatcher} from "../bundle";
import {CachedValue} from "../locking/CachedValue";
import {StateStorage} from "../vscode-objs/StateStorage";
import _ from "lodash";

function isDirectToBundleConfig(
key: keyof BundleConfig,
Expand Down Expand Up @@ -72,8 +73,7 @@ export class ConfigModel implements Disposable {
(oldValue === null && newValue[key] !== undefined) ||
// Old value is not null, and old and new values for the key are different
(oldValue !== null &&
JSON.stringify(oldValue.config[key]) !==
JSON.stringify(newValue[key]))
!_.isEqual(oldValue.config[key], newValue[key]))
) {
this.changeEmitters.get(key)?.emitter.fire();
didAnyConfigChange = true;
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3910,6 +3910,7 @@ __metadata:
fs-extra: ^11.1.1
glob: ^10.3.10
json-schema-to-typescript: ^13.1.1
lodash: ^4.17.21
mocha: ^10.2.0
mock-require: ^3.0.3
nyc: ^15.1.0
Expand Down

0 comments on commit 3d7abe3

Please sign in to comment.