Improve lazy load database/collection offer logic (#768)

This commit is contained in:
victor-meng 2021-05-12 17:13:15 -07:00 committed by GitHub
parent 14e58e5519
commit d76aaca0dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -90,6 +90,7 @@ export default class Collection implements ViewModels.Collection {
public storedProceduresFocused: ko.Observable<boolean>;
public userDefinedFunctionsFocused: ko.Observable<boolean>;
public triggersFocused: ko.Observable<boolean>;
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<boolean>(false);
this.isUserDefinedFunctionsExpanded = ko.observable<boolean>(false);
this.isTriggersExpanded = ko.observable<boolean>(false);
this.isOfferRead = false;
}
public expandCollapseCollection() {
@ -1143,7 +1145,7 @@ export default class Collection implements ViewModels.Collection {
}
public async loadOffer(): Promise<void> {
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,

View File

@ -30,6 +30,7 @@ export default class Database implements ViewModels.Database {
public isDatabaseShared: ko.Computed<boolean>;
public selectedSubnodeKind: ko.Observable<ViewModels.CollectionTabKind>;
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<void> {
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;
}
}