From a698e0863869b7555b17e8067a9687e03b222955 Mon Sep 17 00:00:00 2001 From: victor-meng <56978073+victor-meng@users.noreply.github.com> Date: Mon, 12 Oct 2020 14:00:47 -0700 Subject: [PATCH] Remove database offers cache and get offer directly from database (#268) Currently we maintain a cache of all database offers which can be stale since we have moved to lazy loading the offers. Instead of reading the offer from the cache, we should just find the selected database and get the offer directly by calling `database.offer()`. --- .../SettingsComponent.test.tsx.snap | 24 ------------------- src/Explorer/Panes/AddCollectionPane.ts | 17 ++++--------- 2 files changed, 5 insertions(+), 36 deletions(-) diff --git a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap index 939bfd917..26107a57e 100644 --- a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap +++ b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap @@ -84,9 +84,6 @@ exports[`SettingsComponent renders 1`] = ` "visible": [Function], }, AddCollectionPane { - "_databaseOffers": HashMap { - "container": Object {}, - }, "_isSynapseLinkEnabled": [Function], "autoPilotThroughput": [Function], "autoPilotTiersList": [Function], @@ -586,9 +583,6 @@ exports[`SettingsComponent renders 1`] = ` "_refreshSparkEnabledStateForAccount": [Function], "_resetNotebookWorkspace": [Function], "addCollectionPane": AddCollectionPane { - "_databaseOffers": HashMap { - "container": Object {}, - }, "_isSynapseLinkEnabled": [Function], "autoPilotThroughput": [Function], "autoPilotTiersList": [Function], @@ -1397,9 +1391,6 @@ exports[`SettingsComponent renders 1`] = ` "visible": [Function], }, AddCollectionPane { - "_databaseOffers": HashMap { - "container": Object {}, - }, "_isSynapseLinkEnabled": [Function], "autoPilotThroughput": [Function], "autoPilotTiersList": [Function], @@ -1899,9 +1890,6 @@ exports[`SettingsComponent renders 1`] = ` "_refreshSparkEnabledStateForAccount": [Function], "_resetNotebookWorkspace": [Function], "addCollectionPane": AddCollectionPane { - "_databaseOffers": HashMap { - "container": Object {}, - }, "_isSynapseLinkEnabled": [Function], "autoPilotThroughput": [Function], "autoPilotTiersList": [Function], @@ -2723,9 +2711,6 @@ exports[`SettingsComponent renders 1`] = ` "visible": [Function], }, AddCollectionPane { - "_databaseOffers": HashMap { - "container": Object {}, - }, "_isSynapseLinkEnabled": [Function], "autoPilotThroughput": [Function], "autoPilotTiersList": [Function], @@ -3225,9 +3210,6 @@ exports[`SettingsComponent renders 1`] = ` "_refreshSparkEnabledStateForAccount": [Function], "_resetNotebookWorkspace": [Function], "addCollectionPane": AddCollectionPane { - "_databaseOffers": HashMap { - "container": Object {}, - }, "_isSynapseLinkEnabled": [Function], "autoPilotThroughput": [Function], "autoPilotTiersList": [Function], @@ -4036,9 +4018,6 @@ exports[`SettingsComponent renders 1`] = ` "visible": [Function], }, AddCollectionPane { - "_databaseOffers": HashMap { - "container": Object {}, - }, "_isSynapseLinkEnabled": [Function], "autoPilotThroughput": [Function], "autoPilotTiersList": [Function], @@ -4538,9 +4517,6 @@ exports[`SettingsComponent renders 1`] = ` "_refreshSparkEnabledStateForAccount": [Function], "_resetNotebookWorkspace": [Function], "addCollectionPane": AddCollectionPane { - "_databaseOffers": HashMap { - "container": Object {}, - }, "_isSynapseLinkEnabled": [Function], "autoPilotThroughput": [Function], "autoPilotTiersList": [Function], diff --git a/src/Explorer/Panes/AddCollectionPane.ts b/src/Explorer/Panes/AddCollectionPane.ts index d2b3f6d24..3933f120d 100644 --- a/src/Explorer/Panes/AddCollectionPane.ts +++ b/src/Explorer/Panes/AddCollectionPane.ts @@ -101,12 +101,10 @@ export default class AddCollectionPane extends ContextualPaneBase { public showUpsellMessage: ko.PureComputed; public shouldCreateMongoWildcardIndex: ko.Observable; - private _databaseOffers: HashMap; private _isSynapseLinkEnabled: ko.Computed; constructor(options: AddCollectionPaneOptions) { super(options); - this._databaseOffers = new HashMap(); this.hasAutoPilotV2FeatureFlag = ko.pureComputed(() => this.container.hasAutoPilotV2FeatureFlag()); this.ruToolTipText = ko.pureComputed(() => PricingUtils.getRuToolTipText(this.hasAutoPilotV2FeatureFlag())); this.canConfigureThroughput = ko.pureComputed(() => !this.container.isServerlessEnabled()); @@ -481,7 +479,10 @@ export default class AddCollectionPane extends ContextualPaneBase { } if (!this.databaseCreateNew()) { - this.databaseHasSharedOffer(this._databaseOffers.has(selectedDatabaseId)); + const selectedDatabase: ViewModels.Database = this.container + .databases() + .find((database: ViewModels.Database) => database.id() === selectedDatabaseId); + this.databaseHasSharedOffer(!!selectedDatabase?.offer()); } }); @@ -749,15 +750,7 @@ export default class AddCollectionPane extends ContextualPaneBase { } private _onDatabasesChange(newDatabaseIds: ViewModels.Database[]) { - const cachedDatabaseIdsList = _.map(newDatabaseIds, (database: ViewModels.Database) => { - if (database && database.offer && database.offer()) { - this._databaseOffers.set(database.id(), database.offer()); - } - - return database.id(); - }); - - this.databaseIds(cachedDatabaseIdsList); + this.databaseIds(newDatabaseIds?.map((database: ViewModels.Database) => database.id())); } private _computeOfferThroughput(): number {