Actually working client regeneration. Garbage collection still not cleaning up old clients.
This commit is contained in:
parent
07dacfa04f
commit
4c61cfef58
|
@ -139,30 +139,31 @@ enum SDKSupportedCapabilities {
|
|||
// changeClientEndpoint.......
|
||||
|
||||
let _client: Cosmos.CosmosClient;
|
||||
let _currentClientEndpoint: string;
|
||||
|
||||
export function client(): Cosmos.CosmosClient {
|
||||
console.log(`Called primary client`);
|
||||
const currentUserContextDocumentEndpoint = userContext?.databaseAccount?.properties?.documentEndpoint;
|
||||
console.log(`Current selected endpoint in userContext: ${currentUserContextDocumentEndpoint}`);
|
||||
let mydatabaseAccountEndpoint = "Ahhhhhhhhh";
|
||||
if (_client) {
|
||||
_client
|
||||
.getDatabaseAccount()
|
||||
.then((databaseAccount) => {
|
||||
console.log(
|
||||
`Current primary client endpoint contacted: ${JSON.stringify(
|
||||
databaseAccount.diagnostics.clientSideRequestStatistics.locationEndpointsContacted,
|
||||
)}`,
|
||||
);
|
||||
mydatabaseAccountEndpoint =
|
||||
databaseAccount.diagnostics.clientSideRequestStatistics.locationEndpointsContacted[0];
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error getting database account:", error);
|
||||
});
|
||||
}
|
||||
// let mydatabaseAccountEndpoint = "Ahhhhhhhhh";
|
||||
// if (_client) {
|
||||
// _client
|
||||
// .getDatabaseAccount()
|
||||
// .then((databaseAccount) => {
|
||||
// console.log(
|
||||
// `Current primary client endpoint contacted: ${JSON.stringify(
|
||||
// databaseAccount.diagnostics.clientSideRequestStatistics.locationEndpointsContacted,
|
||||
// )}`,
|
||||
// );
|
||||
// mydatabaseAccountEndpoint =
|
||||
// databaseAccount.diagnostics.clientSideRequestStatistics.locationEndpointsContacted[0];
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// console.error("Error getting database account:", error);
|
||||
// });
|
||||
// }
|
||||
|
||||
if (_client && currentUserContextDocumentEndpoint === mydatabaseAccountEndpoint) {
|
||||
if (_client && currentUserContextDocumentEndpoint === _currentClientEndpoint) {
|
||||
return _client;
|
||||
}
|
||||
|
||||
|
@ -182,8 +183,11 @@ export function client(): Cosmos.CosmosClient {
|
|||
_defaultHeaders["x-ms-cosmos-priority-level"] = PriorityLevel.Default;
|
||||
}
|
||||
|
||||
const clientEndpoint = endpoint() || "https://cosmos.azure.com";
|
||||
_currentClientEndpoint = clientEndpoint;
|
||||
|
||||
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,
|
||||
tokenProvider,
|
||||
userAgentSuffix: "Azure Portal",
|
||||
|
|
|
@ -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(client2().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