mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-25 11:51:07 +00:00
* Add tracing for Execute (submit) query and Upload documents * Trace query closer to iterator operation * Add warnings to values used in Fabric * Fix format * Don't trace execute queries for filtering calls * Remove tracing call for documents tab filtering * Fix failing unit test. --------- Co-authored-by: Jade Welton <jawelton@microsoft.com> Co-authored-by: Sevo Kukol <sevoku@microsoft.com>
46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
import { QueryOperationOptions } from "@azure/cosmos";
|
|
import { Action } from "Shared/Telemetry/TelemetryConstants";
|
|
import * as Constants from "../Common/Constants";
|
|
import { QueryResults } from "../Contracts/ViewModels";
|
|
import * as TelemetryProcessor from "../Shared/Telemetry/TelemetryProcessor";
|
|
|
|
interface QueryResponse {
|
|
// [Todo] remove any
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
resources: any[];
|
|
hasMoreResults: boolean;
|
|
activityId: string;
|
|
requestCharge: number;
|
|
}
|
|
|
|
export interface MinimalQueryIterator {
|
|
fetchNext: (queryOperationOptions?: QueryOperationOptions) => Promise<QueryResponse>;
|
|
}
|
|
|
|
// Pick<QueryIterator<any>, "fetchNext">;
|
|
|
|
export function nextPage(
|
|
documentsIterator: MinimalQueryIterator,
|
|
firstItemIndex: number,
|
|
queryOperationOptions?: QueryOperationOptions,
|
|
): Promise<QueryResults> {
|
|
TelemetryProcessor.traceStart(Action.ExecuteQuery);
|
|
return documentsIterator.fetchNext(queryOperationOptions).then((response) => {
|
|
TelemetryProcessor.traceSuccess(Action.ExecuteQuery, { dataExplorerArea: Constants.Areas.Tab });
|
|
const documents = response.resources;
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
const headers = (response as any).headers || {}; // TODO this is a private key. Remove any
|
|
const itemCount = (documents && documents.length) || 0;
|
|
return {
|
|
documents,
|
|
hasMoreResults: response.hasMoreResults,
|
|
itemCount,
|
|
firstItemIndex: Number(firstItemIndex) + 1,
|
|
lastItemIndex: Number(firstItemIndex) + Number(itemCount),
|
|
headers,
|
|
activityId: response.activityId,
|
|
requestCharge: response.requestCharge,
|
|
};
|
|
});
|
|
}
|