Skip to content

Commit

Permalink
Merge pull request #1204 from visualize-admin/chore/update-debug-panel
Browse files Browse the repository at this point in the history
chore: Add time measuring to SPARQLClientStream and CONSTRUCT queries
  • Loading branch information
bprusinowski authored Oct 6, 2023
2 parents 539249a + e17f7b4 commit 804276d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 48 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ You can also check the [release page](https://github.com/visualize-admin/visuali

- Fixes
- Cascading filters are not stuck anymore in the loading mode in some cases
- Maintenance
- GQL debug panel now includes queries fired through SPARQLClientStream (e.g. hierarchies) and CONSTRUCT queries

# [3.22.8] - 2023-09-29

Expand Down
87 changes: 41 additions & 46 deletions app/gql-flamegraph/devtool.tsx
Original file line number Diff line number Diff line change
@@ -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 }
>;
Expand Down Expand Up @@ -115,35 +114,34 @@ const Flamegraph = ({
}, [timings]);

const barHeight = 15;

return (
<>
<Box
sx={{
position: "relative",
"& svg text": { fontSize: "10px" },
}}
>
<svg width={900} height={50 + rects.length * barHeight}>
<g>
{rects.map((r, i) => (
<Group left={r.x0} top={i * barHeight} key={i}>
<rect
x={0}
y={0}
height={barHeight}
width={r.x1 - r.x0}
fill="#ccc"
/>
<Text verticalAnchor="start" y={2}>
{`${r.duration}ms - ${r.path.join(">")}
<Box
sx={{
position: "relative",
"& svg text": { fontSize: "10px" },
}}
>
<svg width={900} height={50 + rects.length * barHeight}>
<g>
{rects.map((r, i) => (
<Group left={r.x0} top={i * barHeight} key={i}>
<rect
x={0}
y={0}
height={barHeight}
width={r.x1 - r.x0}
fill="#ccc"
/>
<Text verticalAnchor="start" y={2}>
{`${r.duration}ms - ${r.path.join(">")}
`}
</Text>
</Group>
))}
</g>{" "}
</svg>
</Box>
</>
</Text>
</Group>
))}
</g>{" "}
</svg>
</Box>
);
};

Expand Down Expand Up @@ -200,6 +198,7 @@ const AccordionOperation = ({
}
return maxBy(all, (x) => x.end)?.end! - minBy(all, (x) => x.start)?.start!;
}, [result?.extensions?.timings]);

return (
<Accordion {...accordionProps}>
<AccordionSummary>
Expand Down Expand Up @@ -269,7 +268,7 @@ const AccordionOperation = ({
SPARQL queries ({result?.extensions?.queries.length})
</Typography>
<Queries
queries={sortBy(result?.extensions?.queries, (q) => {
queries={sortBy(result?.extensions.queries, (q) => {
return -(q.endTime - q.startTime);
})}
/>
Expand All @@ -281,11 +280,7 @@ const AccordionOperation = ({
);
};

const Queries = ({
queries,
}: {
queries: { startTime: number; endTime: number; text: string }[];
}) => {
const Queries = ({ queries }: { queries: RequestQueryMeta[] }) => {
return (
<div>
{queries.map((q, i) => {
Expand Down
20 changes: 20 additions & 0 deletions app/graphql/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};

Expand Down
5 changes: 3 additions & 2 deletions app/rdf/query-hierarchies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -118,6 +118,7 @@ export const queryHierarchy = async (
if (hierarchies.length === 0) {
return null;
}

const dimensionValuesWithLabels = await getCubeDimensionValuesWithMetadata({
cube: rdimension.cube,
dimension: rdimension.dimension,
Expand Down

1 comment on commit 804276d

@vercel
Copy link

@vercel vercel bot commented on 804276d Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

visualization-tool – ./

visualization-tool-alpha.vercel.app
visualization-tool-git-main-ixt1.vercel.app
visualization-tool-ixt1.vercel.app

Please sign in to comment.