From cbb1e0e5194858ee5ae83d02503d7eabc197b2d2 Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Fri, 6 Oct 2023 11:22:20 +0200 Subject: [PATCH] chore: Add time measuring to SPARQLClientStream and CONSTRUCT queries --- CHANGELOG.md | 3 +- app/gql-flamegraph/devtool.tsx | 87 ++++++++++++++++------------------ app/graphql/context.tsx | 20 ++++++++ app/rdf/query-hierarchies.ts | 5 +- 4 files changed, 66 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc324c66b..cb76e64fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,8 @@ You can also check the [release page](https://github.com/visualize-admin/visuali ## Unreleased -Nothing yet. +- Maintenance + - GQL debug panel now includes queries fired through SPARQLClientStream (e.g. hierarchies) and CONSTRUCT queries # [3.22.8] - 2023-09-29 diff --git a/app/gql-flamegraph/devtool.tsx b/app/gql-flamegraph/devtool.tsx index ee1103b64..703290405 100644 --- a/app/gql-flamegraph/devtool.tsx +++ b/app/gql-flamegraph/devtool.tsx @@ -1,43 +1,42 @@ import { TabContext, TabList, TabPanel } from "@mui/lab"; import { Accordion, - AccordionSummary, AccordionDetails, - Typography, + AccordionProps, + AccordionSummary, Box, + Button, + Divider, Drawer, - AccordionProps, - IconButton, Grow, + IconButton, IconButtonProps, Link, LinkProps, + Switch, + SwitchProps, Tab, - Button, - Divider, + Typography, } from "@mui/material"; -import { Switch, SwitchProps } from "@mui/material"; import { Group } from "@visx/group"; import { Text } from "@visx/text"; import { scaleLinear } from "d3-scale"; -import { OperationDefinitionNode } from "graphql"; -import { print } from "graphql"; +import { OperationDefinitionNode, print } from "graphql"; import maxBy from "lodash/maxBy"; import minBy from "lodash/minBy"; import sortBy from "lodash/sortBy"; import uniqBy from "lodash/uniqBy"; import mitt from "mitt"; -import React, { useEffect, useRef, useState } from "react"; -import { useMemo } from "react"; +import React, { useEffect, useMemo, useRef, useState } from "react"; import { Exchange, Operation, OperationResult } from "urql"; import { pipe, tap } from "wonka"; import useDisclosure from "@/components/use-disclosure"; -import { useFlag, flag, useFlags } from "@/flags"; +import { flag, useFlag, useFlags } from "@/flags"; import { RequestQueryMeta } from "@/graphql/query-meta"; import useEvent from "@/utils/use-event"; -export type Timings = Record< +type Timings = Record< string, { start: number; end: number; children?: Timings } >; @@ -115,35 +114,34 @@ const Flamegraph = ({ }, [timings]); const barHeight = 15; + return ( - <> - - - - {rects.map((r, i) => ( - - - - {`${r.duration}ms - ${r.path.join(">")} + + + + {rects.map((r, i) => ( + + + + {`${r.duration}ms - ${r.path.join(">")} `} - - - ))} - {" "} - - - + + + ))} + {" "} + + ); }; @@ -200,6 +198,7 @@ const AccordionOperation = ({ } return maxBy(all, (x) => x.end)?.end! - minBy(all, (x) => x.start)?.start!; }, [result?.extensions?.timings]); + return ( @@ -269,7 +268,7 @@ const AccordionOperation = ({ SPARQL queries ({result?.extensions?.queries.length}) { + queries={sortBy(result?.extensions.queries, (q) => { return -(q.endTime - q.startTime); })} /> @@ -281,11 +280,7 @@ const AccordionOperation = ({ ); }; -const Queries = ({ - queries, -}: { - queries: { startTime: number; endTime: number; text: string }[]; -}) => { +const Queries = ({ queries }: { queries: RequestQueryMeta[] }) => { return (
{queries.map((q, i) => { diff --git a/app/graphql/context.tsx b/app/graphql/context.tsx index c5116a113..95003b860 100644 --- a/app/graphql/context.tsx +++ b/app/graphql/context.tsx @@ -112,11 +112,31 @@ const setupSparqlClients = ( saveTimingToContext ); + sparqlClient.query.construct = timed( + sparqlClient.query.construct, + saveTimingToContext + ); + + sparqlClientStream.query.select = timed( + sparqlClientStream.query.select, + saveTimingToContext + ); + + sparqlClientStream.query.construct = timed( + sparqlClientStream.query.construct, + saveTimingToContext + ); + geoSparqlClient.query.select = timed( geoSparqlClient.query.select, saveTimingToContext ); + geoSparqlClient.query.construct = timed( + geoSparqlClient.query.construct, + saveTimingToContext + ); + return { sparqlClient, sparqlClientStream, geoSparqlClient }; }; diff --git a/app/rdf/query-hierarchies.ts b/app/rdf/query-hierarchies.ts index c075081cb..b73af0dfb 100644 --- a/app/rdf/query-hierarchies.ts +++ b/app/rdf/query-hierarchies.ts @@ -19,9 +19,9 @@ import { ResolvedDimension } from "@/graphql/shared-types"; import * as ns from "./namespace"; import { getCubeDimensionValuesWithMetadata } from "./queries"; import { - pruneTree, - mapTree, getOptionsFromTree, + mapTree, + pruneTree, regroupTrees, } from "./tree-utils"; @@ -118,6 +118,7 @@ export const queryHierarchy = async ( if (hierarchies.length === 0) { return null; } + const dimensionValuesWithLabels = await getCubeDimensionValuesWithMetadata({ cube: rdimension.cube, dimension: rdimension.dimension,