mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-04-19 12:59:12 +01:00
Fix: Remove duplicate database refresh logic (Fabric). Add logging for collection fetching. (#2426)
* Remove duplicate database refresh logic. Add logging for collection fetching * fix: Fix unit test * fix: Update snapshots to include databasesRefreshed property --------- Co-authored-by: Laurent Nguyen <languye@microsoft.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { ContainerResponse } from "@azure/cosmos";
|
import { ContainerResponse } from "@azure/cosmos";
|
||||||
import { Queries } from "Common/Constants";
|
import { Queries } from "Common/Constants";
|
||||||
|
import * as Logger from "Common/Logger";
|
||||||
import { CosmosDbArtifactType } from "Contracts/FabricMessagesContract";
|
import { CosmosDbArtifactType } from "Contracts/FabricMessagesContract";
|
||||||
import { isFabric, isFabricMirroredKey } from "Platform/Fabric/FabricUtil";
|
import { isFabric, isFabricMirroredKey } from "Platform/Fabric/FabricUtil";
|
||||||
import { AuthType } from "../../AuthType";
|
import { AuthType } from "../../AuthType";
|
||||||
@@ -61,7 +62,14 @@ export async function readCollections(databaseId: string): Promise<DataModels.Co
|
|||||||
return await readCollectionsWithARM(databaseId);
|
return await readCollectionsWithARM(databaseId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.logInfo(`readCollections: calling fetchAll for database ${databaseId}`, "readCollections");
|
||||||
|
const fetchAllStart = Date.now();
|
||||||
const sdkResponse = await client().database(databaseId).containers.readAll().fetchAll();
|
const sdkResponse = await client().database(databaseId).containers.readAll().fetchAll();
|
||||||
|
Logger.logInfo(
|
||||||
|
`readCollections: fetchAll completed for database ${databaseId}, count=${sdkResponse.resources
|
||||||
|
?.length}, durationMs=${Date.now() - fetchAllStart}`,
|
||||||
|
"readCollections",
|
||||||
|
);
|
||||||
return sdkResponse.resources as DataModels.Collection[];
|
return sdkResponse.resources as DataModels.Collection[];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, "ReadCollections", `Error while querying containers for database ${databaseId}`);
|
handleError(error, "ReadCollections", `Error while querying containers for database ${databaseId}`);
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ exports[`SettingsComponent renders 1`] = `
|
|||||||
"conflictResolutionPolicy": [Function],
|
"conflictResolutionPolicy": [Function],
|
||||||
"container": Explorer {
|
"container": Explorer {
|
||||||
"_isInitializingNotebooks": false,
|
"_isInitializingNotebooks": false,
|
||||||
|
"databasesRefreshed": Promise {},
|
||||||
"isFixedCollectionWithSharedThroughputSupported": [Function],
|
"isFixedCollectionWithSharedThroughputSupported": [Function],
|
||||||
"isTabsContentExpanded": [Function],
|
"isTabsContentExpanded": [Function],
|
||||||
"onRefreshDatabasesKeyPress": [Function],
|
"onRefreshDatabasesKeyPress": [Function],
|
||||||
@@ -231,6 +232,7 @@ exports[`SettingsComponent renders 1`] = `
|
|||||||
"conflictResolutionPolicy": [Function],
|
"conflictResolutionPolicy": [Function],
|
||||||
"container": Explorer {
|
"container": Explorer {
|
||||||
"_isInitializingNotebooks": false,
|
"_isInitializingNotebooks": false,
|
||||||
|
"databasesRefreshed": Promise {},
|
||||||
"isFixedCollectionWithSharedThroughputSupported": [Function],
|
"isFixedCollectionWithSharedThroughputSupported": [Function],
|
||||||
"isTabsContentExpanded": [Function],
|
"isTabsContentExpanded": [Function],
|
||||||
"onRefreshDatabasesKeyPress": [Function],
|
"onRefreshDatabasesKeyPress": [Function],
|
||||||
@@ -453,6 +455,7 @@ exports[`SettingsComponent renders 1`] = `
|
|||||||
"conflictResolutionPolicy": [Function],
|
"conflictResolutionPolicy": [Function],
|
||||||
"container": Explorer {
|
"container": Explorer {
|
||||||
"_isInitializingNotebooks": false,
|
"_isInitializingNotebooks": false,
|
||||||
|
"databasesRefreshed": Promise {},
|
||||||
"isFixedCollectionWithSharedThroughputSupported": [Function],
|
"isFixedCollectionWithSharedThroughputSupported": [Function],
|
||||||
"isTabsContentExpanded": [Function],
|
"isTabsContentExpanded": [Function],
|
||||||
"onRefreshDatabasesKeyPress": [Function],
|
"onRefreshDatabasesKeyPress": [Function],
|
||||||
@@ -524,6 +527,7 @@ exports[`SettingsComponent renders 1`] = `
|
|||||||
explorer={
|
explorer={
|
||||||
Explorer {
|
Explorer {
|
||||||
"_isInitializingNotebooks": false,
|
"_isInitializingNotebooks": false,
|
||||||
|
"databasesRefreshed": Promise {},
|
||||||
"isFixedCollectionWithSharedThroughputSupported": [Function],
|
"isFixedCollectionWithSharedThroughputSupported": [Function],
|
||||||
"isTabsContentExpanded": [Function],
|
"isTabsContentExpanded": [Function],
|
||||||
"onRefreshDatabasesKeyPress": [Function],
|
"onRefreshDatabasesKeyPress": [Function],
|
||||||
@@ -692,6 +696,7 @@ exports[`SettingsComponent renders 1`] = `
|
|||||||
"conflictResolutionPolicy": [Function],
|
"conflictResolutionPolicy": [Function],
|
||||||
"container": Explorer {
|
"container": Explorer {
|
||||||
"_isInitializingNotebooks": false,
|
"_isInitializingNotebooks": false,
|
||||||
|
"databasesRefreshed": Promise {},
|
||||||
"isFixedCollectionWithSharedThroughputSupported": [Function],
|
"isFixedCollectionWithSharedThroughputSupported": [Function],
|
||||||
"isTabsContentExpanded": [Function],
|
"isTabsContentExpanded": [Function],
|
||||||
"onRefreshDatabasesKeyPress": [Function],
|
"onRefreshDatabasesKeyPress": [Function],
|
||||||
@@ -763,6 +768,7 @@ exports[`SettingsComponent renders 1`] = `
|
|||||||
explorer={
|
explorer={
|
||||||
Explorer {
|
Explorer {
|
||||||
"_isInitializingNotebooks": false,
|
"_isInitializingNotebooks": false,
|
||||||
|
"databasesRefreshed": Promise {},
|
||||||
"isFixedCollectionWithSharedThroughputSupported": [Function],
|
"isFixedCollectionWithSharedThroughputSupported": [Function],
|
||||||
"isTabsContentExpanded": [Function],
|
"isTabsContentExpanded": [Function],
|
||||||
"onRefreshDatabasesKeyPress": [Function],
|
"onRefreshDatabasesKeyPress": [Function],
|
||||||
|
|||||||
@@ -107,6 +107,12 @@ export default class Explorer {
|
|||||||
|
|
||||||
private static readonly MaxNbDatabasesToAutoExpand = 5;
|
private static readonly MaxNbDatabasesToAutoExpand = 5;
|
||||||
public phoenixClient: PhoenixClient;
|
public phoenixClient: PhoenixClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves when the initial refreshAllDatabases (including collection loading) completes.
|
||||||
|
* Await this instead of calling refreshAllDatabases again to avoid duplicate concurrent loads.
|
||||||
|
*/
|
||||||
|
public databasesRefreshed: Promise<void> = Promise.resolve();
|
||||||
constructor() {
|
constructor() {
|
||||||
const startKey: number = TelemetryProcessor.traceStart(Action.InitializeDataExplorer, {
|
const startKey: number = TelemetryProcessor.traceStart(Action.InitializeDataExplorer, {
|
||||||
dataExplorerArea: Constants.Areas.ResourceTree,
|
dataExplorerArea: Constants.Areas.ResourceTree,
|
||||||
@@ -1197,9 +1203,11 @@ export default class Explorer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (userContext.apiType !== "Postgres" && userContext.apiType !== "VCoreMongo") {
|
if (userContext.apiType !== "Postgres" && userContext.apiType !== "VCoreMongo") {
|
||||||
userContext.authType === AuthType.ResourceToken
|
this.databasesRefreshed =
|
||||||
? this.refreshDatabaseForResourceToken()
|
userContext.authType === AuthType.ResourceToken
|
||||||
: await this.refreshAllDatabases(); // await: we rely on the databases to be loaded before restoring the tabs further in the flow
|
? this.refreshDatabaseForResourceToken()
|
||||||
|
: this.refreshAllDatabases();
|
||||||
|
await this.databasesRefreshed; // await: we rely on the databases to be loaded before restoring the tabs further in the flow
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isFabricNative()) {
|
if (!isFabricNative()) {
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ exports[`AddGlobalSecondaryIndexPanel render default panel 1`] = `
|
|||||||
explorer={
|
explorer={
|
||||||
Explorer {
|
Explorer {
|
||||||
"_isInitializingNotebooks": false,
|
"_isInitializingNotebooks": false,
|
||||||
|
"databasesRefreshed": Promise {},
|
||||||
"isFixedCollectionWithSharedThroughputSupported": [Function],
|
"isFixedCollectionWithSharedThroughputSupported": [Function],
|
||||||
"isTabsContentExpanded": [Function],
|
"isTabsContentExpanded": [Function],
|
||||||
"onRefreshDatabasesKeyPress": [Function],
|
"onRefreshDatabasesKeyPress": [Function],
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ exports[`GitHub Repos Panel should render Default properly 1`] = `
|
|||||||
{
|
{
|
||||||
"container": Explorer {
|
"container": Explorer {
|
||||||
"_isInitializingNotebooks": false,
|
"_isInitializingNotebooks": false,
|
||||||
|
"databasesRefreshed": Promise {},
|
||||||
"isFixedCollectionWithSharedThroughputSupported": [Function],
|
"isFixedCollectionWithSharedThroughputSupported": [Function],
|
||||||
"isTabsContentExpanded": [Function],
|
"isTabsContentExpanded": [Function],
|
||||||
"onRefreshDatabasesKeyPress": [Function],
|
"onRefreshDatabasesKeyPress": [Function],
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ exports[`StringInput Pane should render Create new directory properly 1`] = `
|
|||||||
explorer={
|
explorer={
|
||||||
Explorer {
|
Explorer {
|
||||||
"_isInitializingNotebooks": false,
|
"_isInitializingNotebooks": false,
|
||||||
|
"databasesRefreshed": Promise {},
|
||||||
"isFixedCollectionWithSharedThroughputSupported": [Function],
|
"isFixedCollectionWithSharedThroughputSupported": [Function],
|
||||||
"isTabsContentExpanded": [Function],
|
"isTabsContentExpanded": [Function],
|
||||||
"onRefreshDatabasesKeyPress": [Function],
|
"onRefreshDatabasesKeyPress": [Function],
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ async function configureFabric(): Promise<Explorer> {
|
|||||||
explorer = createExplorerFabricLegacy(initializationMessage, data.version);
|
explorer = createExplorerFabricLegacy(initializationMessage, data.version);
|
||||||
await scheduleRefreshFabricToken(true);
|
await scheduleRefreshFabricToken(true);
|
||||||
resolve(explorer);
|
resolve(explorer);
|
||||||
await explorer.refreshAllDatabases();
|
await explorer.databasesRefreshed;
|
||||||
if (userContext.fabricContext.isVisible) {
|
if (userContext.fabricContext.isVisible) {
|
||||||
firstContainerOpened = true;
|
firstContainerOpened = true;
|
||||||
openFirstContainer(explorer, userContext.fabricContext.databaseName);
|
openFirstContainer(explorer, userContext.fabricContext.databaseName);
|
||||||
@@ -189,7 +189,7 @@ async function configureFabric(): Promise<Explorer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resolve(explorer);
|
resolve(explorer);
|
||||||
await explorer.refreshAllDatabases();
|
await explorer.databasesRefreshed;
|
||||||
|
|
||||||
const { databaseName } = userContext.fabricContext;
|
const { databaseName } = userContext.fabricContext;
|
||||||
if (userContext.fabricContext.isVisible && databaseName) {
|
if (userContext.fabricContext.isVisible && databaseName) {
|
||||||
|
|||||||
Reference in New Issue
Block a user