From d76aaca0ddc9781f090432a6d2b89cdc260cdf5e Mon Sep 17 00:00:00 2001 From: victor-meng <56978073+victor-meng@users.noreply.github.com> Date: Wed, 12 May 2021 17:13:15 -0700 Subject: [PATCH] Improve lazy load database/collection offer logic (#768) --- src/Explorer/Tree/Collection.ts | 5 ++++- src/Explorer/Tree/Database.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Explorer/Tree/Collection.ts b/src/Explorer/Tree/Collection.ts index f92871f27..b7820d35d 100644 --- a/src/Explorer/Tree/Collection.ts +++ b/src/Explorer/Tree/Collection.ts @@ -90,6 +90,7 @@ export default class Collection implements ViewModels.Collection { public storedProceduresFocused: ko.Observable; public userDefinedFunctionsFocused: ko.Observable; public triggersFocused: ko.Observable; + private isOfferRead: boolean; constructor(container: Explorer, databaseId: string, data: DataModels.Collection) { this.nodeKind = "Collection"; @@ -201,6 +202,7 @@ export default class Collection implements ViewModels.Collection { this.isStoredProceduresExpanded = ko.observable(false); this.isUserDefinedFunctionsExpanded = ko.observable(false); this.isTriggersExpanded = ko.observable(false); + this.isOfferRead = false; } public expandCollapseCollection() { @@ -1143,7 +1145,7 @@ export default class Collection implements ViewModels.Collection { } public async loadOffer(): Promise { - if (!this.container.isServerlessEnabled() && !this.offer()) { + if (!this.isOfferRead && !this.container.isServerlessEnabled() && !this.offer()) { const startKey: number = TelemetryProcessor.traceStart(Action.LoadOffers, { databaseName: this.databaseId, collectionName: this.id(), @@ -1158,6 +1160,7 @@ export default class Collection implements ViewModels.Collection { try { this.offer(await readCollectionOffer(params)); this.usageSizeInKB(await getCollectionUsageSizeInKB(this.databaseId, this.id())); + this.isOfferRead = true; TelemetryProcessor.traceSuccess( Action.LoadOffers, diff --git a/src/Explorer/Tree/Database.ts b/src/Explorer/Tree/Database.ts index 84911515b..f9cc2e605 100644 --- a/src/Explorer/Tree/Database.ts +++ b/src/Explorer/Tree/Database.ts @@ -30,6 +30,7 @@ export default class Database implements ViewModels.Database { public isDatabaseShared: ko.Computed; public selectedSubnodeKind: ko.Observable; public junoClient: JunoClient; + private isOfferRead: boolean; constructor(container: Explorer, data: any) { this.nodeKind = "Database"; @@ -45,6 +46,7 @@ export default class Database implements ViewModels.Database { return this.offer && !!this.offer(); }); this.junoClient = new JunoClient(); + this.isOfferRead = false; } public onSettingsClick = () => { @@ -214,12 +216,13 @@ export default class Database implements ViewModels.Database { } public async loadOffer(): Promise { - if (!this.container.isServerlessEnabled() && !this.offer()) { + if (!this.isOfferRead && !this.container.isServerlessEnabled() && !this.offer()) { const params: DataModels.ReadDatabaseOfferParams = { databaseId: this.id(), databaseResourceId: this.self, }; this.offer(await readDatabaseOffer(params)); + this.isOfferRead = true; } }