mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-05-19 14:54:40 +01:00
* Execute the queries with high/low priority * improvement made to the Cosmos client and created separate plugin class for setting priority header * added test cases for the priority execution utility * removed unwanted code * fix compile time issues * fix compile time issues * fixed lint and stylinkg issues * fixed lint and styling issues * skip the lint check for src/Utils/PriorityBasedExecutionUtils.ts * incorporating review comments, added the default priority level changes * changed the priority to default instead of low * removed the unwanted if condition --------- Co-authored-by: Faiz Chachiya <faizchachiya@microsoft.com>
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import * as Cosmos from "@azure/cosmos";
|
|
import { LocalStorageUtility, StorageKey } from "Shared/StorageUtility";
|
|
import { PriorityLevel } from "../Common/Constants";
|
|
|
|
export function isRelevantRequest(requestContext: Cosmos.RequestContext): boolean {
|
|
return (
|
|
requestContext.resourceType === Cosmos.ResourceType.item ||
|
|
requestContext.resourceType === Cosmos.ResourceType.conflicts ||
|
|
(requestContext.resourceType === Cosmos.ResourceType.sproc &&
|
|
requestContext.operationType === Cosmos.OperationType.Execute)
|
|
);
|
|
}
|
|
|
|
export function getPriorityLevel(): PriorityLevel {
|
|
const priorityLevel = LocalStorageUtility.getEntryString(StorageKey.PriorityLevel);
|
|
if (priorityLevel && Object.values(PriorityLevel).includes(priorityLevel)) {
|
|
return priorityLevel as PriorityLevel;
|
|
} else {
|
|
return PriorityLevel.Default;
|
|
}
|
|
}
|
|
|
|
export const requestPlugin: Cosmos.Plugin<any> = async (requestContext, next) => {
|
|
if (isRelevantRequest(requestContext)) {
|
|
const priorityLevel: PriorityLevel = getPriorityLevel();
|
|
requestContext.headers["x-ms-cosmos-priority-level"] = priorityLevel as string;
|
|
}
|
|
return next(requestContext);
|
|
};
|