mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-11-25 06:56:38 +00:00
Revert "Setup so that client regenerates when another endpoint is selected."
This reverts commit bbe4a755a0
.
This commit is contained in:
parent
b45e667d51
commit
fd8670ee9b
@ -131,8 +131,6 @@ enum SDKSupportedCapabilities {
|
||||
// Need to put in some kind of function here to recreate the CosmosClient with a new endpoint.
|
||||
// changeClientEndpoint.......
|
||||
|
||||
// let _clients: Map<string, Cosmos.CosmosClient> = new Map();
|
||||
|
||||
let _client: Cosmos.CosmosClient;
|
||||
|
||||
export function client(): Cosmos.CosmosClient {
|
||||
@ -157,13 +155,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;
|
||||
}
|
||||
@ -185,7 +176,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",
|
||||
@ -229,11 +220,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);
|
||||
}
|
||||
|
@ -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 }];
|
||||
|
@ -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<ItemDefinition & Resource> => {
|
||||
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 => {
|
||||
|
@ -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<Item> => {
|
||||
@ -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()}`);
|
||||
|
Loading…
Reference in New Issue
Block a user