mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-11-25 06:56:38 +00:00
Actually working client regeneration. Garbage collection still not cleaning up old clients.
This commit is contained in:
parent
fd8670ee9b
commit
029382b1bd
@ -132,30 +132,31 @@ enum SDKSupportedCapabilities {
|
|||||||
// changeClientEndpoint.......
|
// changeClientEndpoint.......
|
||||||
|
|
||||||
let _client: Cosmos.CosmosClient;
|
let _client: Cosmos.CosmosClient;
|
||||||
|
let _currentClientEndpoint: string;
|
||||||
|
|
||||||
export function client(): Cosmos.CosmosClient {
|
export function client(): Cosmos.CosmosClient {
|
||||||
console.log(`Called primary client`);
|
console.log(`Called primary client`);
|
||||||
const currentUserContextDocumentEndpoint = userContext?.databaseAccount?.properties?.documentEndpoint;
|
const currentUserContextDocumentEndpoint = userContext?.databaseAccount?.properties?.documentEndpoint;
|
||||||
console.log(`Current selected endpoint in userContext: ${currentUserContextDocumentEndpoint}`);
|
console.log(`Current selected endpoint in userContext: ${currentUserContextDocumentEndpoint}`);
|
||||||
let mydatabaseAccountEndpoint = "Ahhhhhhhhh";
|
// let mydatabaseAccountEndpoint = "Ahhhhhhhhh";
|
||||||
if (_client) {
|
// if (_client) {
|
||||||
_client
|
// _client
|
||||||
.getDatabaseAccount()
|
// .getDatabaseAccount()
|
||||||
.then((databaseAccount) => {
|
// .then((databaseAccount) => {
|
||||||
console.log(
|
// console.log(
|
||||||
`Current primary client endpoint contacted: ${JSON.stringify(
|
// `Current primary client endpoint contacted: ${JSON.stringify(
|
||||||
databaseAccount.diagnostics.clientSideRequestStatistics.locationEndpointsContacted,
|
// databaseAccount.diagnostics.clientSideRequestStatistics.locationEndpointsContacted,
|
||||||
)}`,
|
// )}`,
|
||||||
);
|
// );
|
||||||
mydatabaseAccountEndpoint =
|
// mydatabaseAccountEndpoint =
|
||||||
databaseAccount.diagnostics.clientSideRequestStatistics.locationEndpointsContacted[0];
|
// databaseAccount.diagnostics.clientSideRequestStatistics.locationEndpointsContacted[0];
|
||||||
})
|
// })
|
||||||
.catch((error) => {
|
// .catch((error) => {
|
||||||
console.error("Error getting database account:", error);
|
// console.error("Error getting database account:", error);
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (_client && currentUserContextDocumentEndpoint === mydatabaseAccountEndpoint) {
|
if (_client && currentUserContextDocumentEndpoint === _currentClientEndpoint) {
|
||||||
return _client;
|
return _client;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,8 +176,11 @@ export function client(): Cosmos.CosmosClient {
|
|||||||
_defaultHeaders["x-ms-cosmos-priority-level"] = PriorityLevel.Default;
|
_defaultHeaders["x-ms-cosmos-priority-level"] = PriorityLevel.Default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clientEndpoint = endpoint() || "https://cosmos.azure.com";
|
||||||
|
_currentClientEndpoint = clientEndpoint;
|
||||||
|
|
||||||
const options: Cosmos.CosmosClientOptions = {
|
const options: Cosmos.CosmosClientOptions = {
|
||||||
endpoint: endpoint() || "https://cosmos.azure.com", // CosmosClient gets upset if we pass a bad URL. This should never actually get called
|
endpoint: clientEndpoint, // 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",
|
||||||
|
@ -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(client2().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 => {
|
||||||
|
@ -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()}`);
|
||||||
|
Loading…
Reference in New Issue
Block a user