Skip to content

Commit

Permalink
Small throughput related improvements. (#2465)
Browse files Browse the repository at this point in the history
If a container has shared throughput, show the database offer instead.
Add a new command to show the database offer.
  • Loading branch information
sevoku authored Dec 3, 2024
1 parent 5190357 commit 2de506e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,11 @@
"command": "cosmosDB.viewDocDBCollectionOffer",
"title": "View Container Offer"
},
{
"category": "NoSQL",
"command": "cosmosDB.viewDocDBDatabaseOffer",
"title": "View Database Offer"
},
{
"category": "NoSQL",
"command": "cosmosDB.writeNoSqlQuery",
Expand Down Expand Up @@ -895,6 +900,11 @@
"when": "view =~ /azure(ResourceGroups|Workspace|FocusView)/ && viewItem == cosmosDBDocumentCollection",
"group": "1@5"
},
{
"command": "cosmosDB.viewDocDBDatabaseOffer",
"when": "view =~ /azure(ResourceGroups|Workspace|FocusView)/ && viewItem == cosmosDBDocumentDatabase",
"group": "1@5"
},
{
"command": "cosmosDB.deleteDocDBDocument",
"when": "view =~ /azure(ResourceGroups|Workspace|FocusView)/ && viewItem == cosmosDBDocument",
Expand Down
14 changes: 12 additions & 2 deletions src/docdb/commands/viewDocDBCollectionOffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ export async function viewDocDBCollectionOffer(context: IActionContext, node?: D
node = await pickDocDBAccount<DocDBCollectionTreeItem>(context, DocDBCollectionTreeItem.contextValue);
}
const client = node.root.getCosmosClient();
const offer = await node.getContainerClient(client).readOffer();
await vscodeUtil.showNewFile(JSON.stringify(offer.resource, undefined, 2), `offer of ${node.label}`, '.json');
let offer = await node.getContainerClient(client).readOffer();
if (!offer.resource) {
// collections with shared throughput will not have an offer, show the database offer instead
offer = await node.parent.getDatabaseClient(client).readOffer();
await vscodeUtil.showNewFile(
JSON.stringify(offer.resource, undefined, 2),
`offer of ${node.parent.label}`,
'.json',
);
} else {
await vscodeUtil.showNewFile(JSON.stringify(offer.resource, undefined, 2), `offer of ${node.label}`, '.json');
}
}
20 changes: 20 additions & 0 deletions src/docdb/commands/viewDocDBDatabaseOffer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { type IActionContext, type ITreeItemPickerContext } from '@microsoft/vscode-azext-utils';
import * as vscodeUtil from '../../utils/vscodeUtils';
import { DocDBDatabaseTreeItem } from '../tree/DocDBDatabaseTreeItem';
import { pickDocDBAccount } from './pickDocDBAccount';

export async function viewDocDBDatabaseOffer(context: IActionContext, node?: DocDBDatabaseTreeItem): Promise<void> {
const suppressCreateContext: ITreeItemPickerContext = context;
suppressCreateContext.suppressCreatePick = true;
if (!node) {
node = await pickDocDBAccount<DocDBDatabaseTreeItem>(context, DocDBDatabaseTreeItem.contextValue);
}
const client = node.root.getCosmosClient();
const offer = await node.getDatabaseClient(client).readOffer();
await vscodeUtil.showNewFile(JSON.stringify(offer.resource, undefined, 2), `offer of ${node.label}`, '.json');
}
2 changes: 2 additions & 0 deletions src/docdb/registerDocDBCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { openNoSqlQueryEditor } from './commands/openNoSqlQueryEditor';
import { openStoredProcedure } from './commands/openStoredProcedure';
import { openTrigger } from './commands/openTrigger';
import { viewDocDBCollectionOffer } from './commands/viewDocDBCollectionOffer';
import { viewDocDBDatabaseOffer } from './commands/viewDocDBDatabaseOffer';
import { writeNoSqlQuery } from './commands/writeNoSqlQuery';
import { NoSqlCodeLensProvider } from './NoSqlCodeLensProvider';

Expand All @@ -48,6 +49,7 @@ export function registerDocDBCommands(): void {

registerCommandWithTreeNodeUnwrapping('cosmosDB.createDocDBCollection', createDocDBCollection);
registerCommandWithTreeNodeUnwrapping('cosmosDB.deleteDocDBDatabase', deleteDocDBDatabase);
registerCommandWithTreeNodeUnwrapping('cosmosDB.viewDocDBDatabaseOffer', viewDocDBDatabaseOffer);

// #endregion

Expand Down

0 comments on commit 2de506e

Please sign in to comment.