diff --git a/src/Common/CosmosClient.ts b/src/Common/CosmosClient.ts index ee72ed60e..982f35e95 100644 --- a/src/Common/CosmosClient.ts +++ b/src/Common/CosmosClient.ts @@ -138,8 +138,6 @@ enum SDKSupportedCapabilities { // Need to put in some kind of function here to recreate the CosmosClient with a new endpoint. // changeClientEndpoint....... -// let _clients: Map = new Map(); - let _client: Cosmos.CosmosClient; export function client(): Cosmos.CosmosClient { @@ -164,13 +162,6 @@ export function client(): Cosmos.CosmosClient { }); } - const retrievedEndpoint = endpoint() || "https://cosmos.azure.com"; - - // if (_clients.has(retrievedEndpoint)) { - // console.log(`Current Client List: ${JSON.stringify(_clients)}`); - // return _clients.get(retrievedEndpoint); - // } - if (_client && currentUserContextDocumentEndpoint === mydatabaseAccountEndpoint) { return _client; } @@ -192,7 +183,7 @@ export function client(): Cosmos.CosmosClient { } const options: Cosmos.CosmosClientOptions = { - endpoint: retrievedEndpoint, // CosmosClient gets upset if we pass a bad URL. This should never actually get called + endpoint: endpoint() || "https://cosmos.azure.com", // CosmosClient gets upset if we pass a bad URL. This should never actually get called key: userContext.masterKey, tokenProvider, userAgentSuffix: "Azure Portal", @@ -236,11 +227,6 @@ export function client(): Cosmos.CosmosClient { (options as any).plugins = plugins; } - _client = null; _client = new Cosmos.CosmosClient(options); return _client; - - // _clients.set(retrievedEndpoint, new Cosmos.CosmosClient(options)); - - // return _clients.get(retrievedEndpoint); } diff --git a/src/Common/ReadRegionCosmosClient.ts b/src/Common/ReadRegionCosmosClient.ts index d10623731..235fd6042 100644 --- a/src/Common/ReadRegionCosmosClient.ts +++ b/src/Common/ReadRegionCosmosClient.ts @@ -166,24 +166,24 @@ export function client2(): Cosmos.CosmosClient { }; // Account details from userContext. - // console.log(`userContext details: ${JSON.stringify(userContext)}`); - // console.log(`userContext.databaseaccount details: ${JSON.stringify(userContext.databaseAccount)}`); + console.log(`userContext details: ${JSON.stringify(userContext)}`); + console.log(`userContext.databaseaccount details: ${JSON.stringify(userContext.databaseAccount)}`); console.log( `userContext?.databaseAccount?.properties?.documentEndpoint details: ${JSON.stringify( userContext?.databaseAccount?.properties?.documentEndpoint, )}`, ); console.log(`userContext?.endpoint details: ${JSON.stringify(userContext?.endpoint)}`); - // console.log( - // `userContext?.databaseAccount?.properties?.readLocations details: ${JSON.stringify( - // userContext?.databaseAccount?.properties?.readLocations, - // )}`, - // ); - // console.log( - // `userContext?.databaseAccount?.properties?.writeLocations details: ${JSON.stringify( - // userContext?.databaseAccount?.properties?.writeLocations, - // )}`, - // ); + console.log( + `userContext?.databaseAccount?.properties?.readLocations details: ${JSON.stringify( + userContext?.databaseAccount?.properties?.readLocations, + )}`, + ); + console.log( + `userContext?.databaseAccount?.properties?.writeLocations details: ${JSON.stringify( + userContext?.databaseAccount?.properties?.writeLocations, + )}`, + ); if (configContext.PROXY_PATH !== undefined) { (options as any).plugins = [{ on: "request", plugin: requestPlugin2 }]; diff --git a/src/Common/dataAccess/queryDocuments.ts b/src/Common/dataAccess/queryDocuments.ts index 848c10c77..bb8eb1241 100644 --- a/src/Common/dataAccess/queryDocuments.ts +++ b/src/Common/dataAccess/queryDocuments.ts @@ -1,8 +1,8 @@ import { FeedOptions, ItemDefinition, QueryIterator, Resource } from "@azure/cosmos"; import { LocalStorageUtility, StorageKey } from "../../Shared/StorageUtility"; import { Queries } from "../Constants"; -// import { client2 } from "../ReadRegionCosmosClient"; -import { client } from "../CosmosClient"; +import { client2 } from "../ReadRegionCosmosClient"; +// import { client } from "../CosmosClient"; export const queryDocuments = ( databaseId: string, @@ -11,9 +11,9 @@ export const queryDocuments = ( options: FeedOptions, ): QueryIterator => { options = getCommonQueryOptions(options); - console.log(`${JSON.stringify(client().getReadEndpoint())}`); - // return client2().database(databaseId).container(containerId).items.query(query, options); - return client().database(databaseId).container(containerId).items.query(query, options); + console.log(`${JSON.stringify(client2().getReadEndpoint())}`); + return client2().database(databaseId).container(containerId).items.query(query, options); + // return client().database(databaseId).container(containerId).items.query(query, options); }; export const getCommonQueryOptions = (options: FeedOptions): FeedOptions => { diff --git a/src/Common/dataAccess/readDocument.ts b/src/Common/dataAccess/readDocument.ts index 12d3f0fcb..78b20bfe7 100644 --- a/src/Common/dataAccess/readDocument.ts +++ b/src/Common/dataAccess/readDocument.ts @@ -3,10 +3,10 @@ import { CollectionBase } from "../../Contracts/ViewModels"; import DocumentId from "../../Explorer/Tree/DocumentId"; import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { HttpHeaders } from "../Constants"; -import { client } from "../CosmosClient"; +// import { client } from "../CosmosClient"; import { getEntityName } from "../DocumentUtility"; import { handleError } from "../ErrorHandlingUtils"; -// import { client2 } from "../ReadRegionCosmosClient"; +import { client2 } from "../ReadRegionCosmosClient"; import { getPartitionKeyValue } from "./getPartitionKeyValue"; export const readDocument = async (collection: CollectionBase, documentId: DocumentId): Promise => { @@ -20,18 +20,18 @@ export const readDocument = async (collection: CollectionBase, documentId: Docum [HttpHeaders.partitionKey]: documentId.partitionKeyValue, } : {}; - const response = await client() - .database(collection.databaseId) - .container(collection.id()) - .item(documentId.id(), getPartitionKeyValue(documentId)) - .read(options); - - // const response = await client2() + // const response = await client() // .database(collection.databaseId) // .container(collection.id()) // .item(documentId.id(), getPartitionKeyValue(documentId)) // .read(options); + const response = await client2() + .database(collection.databaseId) + .container(collection.id()) + .item(documentId.id(), getPartitionKeyValue(documentId)) + .read(options); + return response?.resource; } catch (error) { handleError(error, "ReadDocument", `Failed to read ${entityName} ${documentId.id()}`);