Revert "Setup so that client regenerates when another endpoint is selected."

This reverts commit bbe4a755a0.
This commit is contained in:
Craig Boger (from Dev Box) 2024-02-16 17:46:02 -08:00
parent 638d9c1fae
commit 07dacfa04f
4 changed files with 27 additions and 41 deletions

View File

@ -138,8 +138,6 @@ enum SDKSupportedCapabilities {
// Need to put in some kind of function here to recreate the CosmosClient with a new endpoint. // Need to put in some kind of function here to recreate the CosmosClient with a new endpoint.
// changeClientEndpoint....... // changeClientEndpoint.......
// let _clients: Map<string, Cosmos.CosmosClient> = new Map();
let _client: Cosmos.CosmosClient; let _client: Cosmos.CosmosClient;
export function 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) { if (_client && currentUserContextDocumentEndpoint === mydatabaseAccountEndpoint) {
return _client; return _client;
} }
@ -192,7 +183,7 @@ export function client(): Cosmos.CosmosClient {
} }
const options: Cosmos.CosmosClientOptions = { 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, key: userContext.masterKey,
tokenProvider, tokenProvider,
userAgentSuffix: "Azure Portal", userAgentSuffix: "Azure Portal",
@ -236,11 +227,6 @@ export function client(): Cosmos.CosmosClient {
(options as any).plugins = plugins; (options as any).plugins = plugins;
} }
_client = null;
_client = new Cosmos.CosmosClient(options); _client = new Cosmos.CosmosClient(options);
return _client; return _client;
// _clients.set(retrievedEndpoint, new Cosmos.CosmosClient(options));
// return _clients.get(retrievedEndpoint);
} }

View File

@ -166,24 +166,24 @@ export function client2(): Cosmos.CosmosClient {
}; };
// Account details from userContext. // Account details from userContext.
// console.log(`userContext details: ${JSON.stringify(userContext)}`); console.log(`userContext details: ${JSON.stringify(userContext)}`);
// console.log(`userContext.databaseaccount details: ${JSON.stringify(userContext.databaseAccount)}`); console.log(`userContext.databaseaccount details: ${JSON.stringify(userContext.databaseAccount)}`);
console.log( console.log(
`userContext?.databaseAccount?.properties?.documentEndpoint details: ${JSON.stringify( `userContext?.databaseAccount?.properties?.documentEndpoint details: ${JSON.stringify(
userContext?.databaseAccount?.properties?.documentEndpoint, userContext?.databaseAccount?.properties?.documentEndpoint,
)}`, )}`,
); );
console.log(`userContext?.endpoint details: ${JSON.stringify(userContext?.endpoint)}`); console.log(`userContext?.endpoint details: ${JSON.stringify(userContext?.endpoint)}`);
// console.log( console.log(
// `userContext?.databaseAccount?.properties?.readLocations details: ${JSON.stringify( `userContext?.databaseAccount?.properties?.readLocations details: ${JSON.stringify(
// userContext?.databaseAccount?.properties?.readLocations, userContext?.databaseAccount?.properties?.readLocations,
// )}`, )}`,
// ); );
// console.log( console.log(
// `userContext?.databaseAccount?.properties?.writeLocations details: ${JSON.stringify( `userContext?.databaseAccount?.properties?.writeLocations details: ${JSON.stringify(
// userContext?.databaseAccount?.properties?.writeLocations, userContext?.databaseAccount?.properties?.writeLocations,
// )}`, )}`,
// ); );
if (configContext.PROXY_PATH !== undefined) { if (configContext.PROXY_PATH !== undefined) {
(options as any).plugins = [{ on: "request", plugin: requestPlugin2 }]; (options as any).plugins = [{ on: "request", plugin: requestPlugin2 }];

View File

@ -1,8 +1,8 @@
import { FeedOptions, ItemDefinition, QueryIterator, Resource } from "@azure/cosmos"; import { FeedOptions, ItemDefinition, QueryIterator, Resource } from "@azure/cosmos";
import { LocalStorageUtility, StorageKey } from "../../Shared/StorageUtility"; import { LocalStorageUtility, StorageKey } from "../../Shared/StorageUtility";
import { Queries } from "../Constants"; import { Queries } from "../Constants";
// import { client2 } from "../ReadRegionCosmosClient"; import { client2 } from "../ReadRegionCosmosClient";
import { client } from "../CosmosClient"; // import { client } from "../CosmosClient";
export const queryDocuments = ( export const queryDocuments = (
databaseId: string, databaseId: string,
@ -11,9 +11,9 @@ export const queryDocuments = (
options: FeedOptions, options: FeedOptions,
): QueryIterator<ItemDefinition & Resource> => { ): QueryIterator<ItemDefinition & Resource> => {
options = getCommonQueryOptions(options); options = getCommonQueryOptions(options);
console.log(`${JSON.stringify(client().getReadEndpoint())}`); console.log(`${JSON.stringify(client2().getReadEndpoint())}`);
// return client2().database(databaseId).container(containerId).items.query(query, options); return client2().database(databaseId).container(containerId).items.query(query, options);
return client().database(databaseId).container(containerId).items.query(query, options); // return client().database(databaseId).container(containerId).items.query(query, options);
}; };
export const getCommonQueryOptions = (options: FeedOptions): FeedOptions => { export const getCommonQueryOptions = (options: FeedOptions): FeedOptions => {

View File

@ -3,10 +3,10 @@ import { CollectionBase } from "../../Contracts/ViewModels";
import DocumentId from "../../Explorer/Tree/DocumentId"; import DocumentId from "../../Explorer/Tree/DocumentId";
import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
import { HttpHeaders } from "../Constants"; import { HttpHeaders } from "../Constants";
import { client } from "../CosmosClient"; // import { client } from "../CosmosClient";
import { getEntityName } from "../DocumentUtility"; import { getEntityName } from "../DocumentUtility";
import { handleError } from "../ErrorHandlingUtils"; import { handleError } from "../ErrorHandlingUtils";
// import { client2 } from "../ReadRegionCosmosClient"; import { client2 } from "../ReadRegionCosmosClient";
import { getPartitionKeyValue } from "./getPartitionKeyValue"; import { getPartitionKeyValue } from "./getPartitionKeyValue";
export const readDocument = async (collection: CollectionBase, documentId: DocumentId): Promise<Item> => { export const readDocument = async (collection: CollectionBase, documentId: DocumentId): Promise<Item> => {
@ -20,18 +20,18 @@ export const readDocument = async (collection: CollectionBase, documentId: Docum
[HttpHeaders.partitionKey]: documentId.partitionKeyValue, [HttpHeaders.partitionKey]: documentId.partitionKeyValue,
} }
: {}; : {};
const response = await client() // const response = await client()
.database(collection.databaseId)
.container(collection.id())
.item(documentId.id(), getPartitionKeyValue(documentId))
.read(options);
// const response = await client2()
// .database(collection.databaseId) // .database(collection.databaseId)
// .container(collection.id()) // .container(collection.id())
// .item(documentId.id(), getPartitionKeyValue(documentId)) // .item(documentId.id(), getPartitionKeyValue(documentId))
// .read(options); // .read(options);
const response = await client2()
.database(collection.databaseId)
.container(collection.id())
.item(documentId.id(), getPartitionKeyValue(documentId))
.read(options);
return response?.resource; return response?.resource;
} catch (error) { } catch (error) {
handleError(error, "ReadDocument", `Failed to read ${entityName} ${documentId.id()}`); handleError(error, "ReadDocument", `Failed to read ${entityName} ${documentId.id()}`);