Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Initial DataCubeComponents / dimension values query optimizations #1360

Merged
merged 19 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/charts/area/chart-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const ChartAreasVisualization = ({
iri: cube.iri,
componentIris,
joinBy: cube.joinBy,
loadValues: true,
})),
},
});
Expand Down
1 change: 1 addition & 0 deletions app/charts/column/chart-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const ChartColumnsVisualization = ({
iri: cube.iri,
componentIris,
joinBy: cube.joinBy,
loadValues: true,
})),
},
});
Expand Down
1 change: 1 addition & 0 deletions app/charts/combo/chart-combo-line-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const ChartComboLineColumnVisualization = (
iri: cube.iri,
componentIris,
joinBy: cube.joinBy,
loadValues: true,
})),
},
});
Expand Down
1 change: 1 addition & 0 deletions app/charts/combo/chart-combo-line-dual.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const ChartComboLineDualVisualization = (
iri: cube.iri,
componentIris,
joinBy: cube.joinBy,
loadValues: true,
})),
},
});
Expand Down
1 change: 1 addition & 0 deletions app/charts/combo/chart-combo-line-single.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const ChartComboLineSingleVisualization = (
iri: cube.iri,
componentIris,
joinBy: cube.joinBy,
loadValues: true,
})),
},
});
Expand Down
1 change: 1 addition & 0 deletions app/charts/line/chart-lines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const ChartLinesVisualization = ({
iri: cube.iri,
componentIris,
joinBy: cube.joinBy,
loadValues: true,
})),
},
});
Expand Down
1 change: 1 addition & 0 deletions app/charts/map/chart-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const ChartMapVisualization = ({
iri: cube.iri,
componentIris,
joinBy: cube.joinBy,
loadValues: true,
})),
},
});
Expand Down
1 change: 1 addition & 0 deletions app/charts/pie/chart-pie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const ChartPieVisualization = ({
iri: cube.iri,
componentIris,
joinBy: cube.joinBy,
loadValues: true,
})),
},
});
Expand Down
1 change: 1 addition & 0 deletions app/charts/scatterplot/chart-scatterplot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const ChartScatterplotVisualization = ({
iri: cube.iri,
componentIris,
joinBy: cube.joinBy,
loadValues: true,
})),
},
});
Expand Down
3 changes: 2 additions & 1 deletion app/charts/shared/chart-data-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ const DataFilter = (props: DataFilterProps) => {
{
iri: cubeIri,
componentIris: [dimensionIri],
filters: keys.length > 0 ? interactiveFilters : undefined,
filters: keys.length > 1 ? interactiveFilters : undefined,
bprusinowski marked this conversation as resolved.
Show resolved Hide resolved
loadValues: true,
},
],
// This is important for urql not to think that filters
Expand Down
1 change: 1 addition & 0 deletions app/charts/table/chart-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const ChartTableVisualization = ({
iri: cube.iri,
componentIris,
joinBy: cube.joinBy,
loadValues: true,
})),
},
});
Expand Down
3 changes: 2 additions & 1 deletion app/components/chart-filters-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const ChartFiltersList = (props: ChartFiltersListProps) => {
componentIris: filter.componentIris,
filters: filter.filters,
joinBy: filter.joinBy,
loadValues: true,
})) ?? [],
},
pause: !filters,
Expand All @@ -72,7 +73,7 @@ export const ChartFiltersList = (props: ChartFiltersListProps) => {
return [];
}

const dimension = dimensions.find(
const dimension = data.dataCubesComponents.dimensions.find(
(d) => d.iri === iri && d.cubeIri === filter.iri
);

Expand Down
17 changes: 16 additions & 1 deletion app/components/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Box,
BoxProps,
ButtonBase,
CircularProgress,
FormControlLabel,
FormControlLabelProps,
InputLabel,
Expand Down Expand Up @@ -353,9 +354,23 @@ export const Select = ({
<LoadingMenuPaperContext.Provider value={loading}>
<Box sx={{ width: "100%", ...sx }}>
{label && (
<Label htmlFor={id} smaller sx={{ my: "6px" }}>
<Label
htmlFor={id}
smaller
sx={{ display: "flex", alignItems: "center", my: "6px" }}
>
{label}
{controls}
{loading && (
<CircularProgress
size={12}
sx={{
color: "grey.700",
display: "inline-block",
marginLeft: 2,
}}
/>
)}
</Label>
)}
<MUISelect
Expand Down
40 changes: 36 additions & 4 deletions app/configurator/components/chart-configurator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { makeStyles } from "@mui/styles";
import isEmpty from "lodash/isEmpty";
import isEqual from "lodash/isEqual";
import pickBy from "lodash/pickBy";
import sortBy from "lodash/sortBy";
import React, { useEffect, useMemo, useRef, useState } from "react";
import {
Expand Down Expand Up @@ -90,14 +91,40 @@ import { useLocale } from "@/locales/use-locale";
import useEvent from "@/utils/use-event";

type DataFilterSelectGenericProps = {
dimension: Dimension;
rawDimension: Dimension;
filterDimensionIris: string[];
index: number;
disabled?: boolean;
onRemove: () => void;
};

const DataFilterSelectGeneric = (props: DataFilterSelectGenericProps) => {
const { dimension, index, disabled, onRemove } = props;
const { rawDimension, filterDimensionIris, index, disabled, onRemove } =
props;
const locale = useLocale();
const [state] = useConfiguratorState();
const chartConfig = getChartConfig(state);
const [{ data, fetching }] = useDataCubesComponentsQuery({
variables: {
sourceType: state.dataSource.type,
sourceUrl: state.dataSource.url,
locale,
cubeFilters: chartConfig.cubes.map((cube) => {
const rawFilters = pickBy(cube.filters, (_, key) =>
filterDimensionIris.includes(key)
);
return {
iri: cube.iri,
joinBy: cube.joinBy,
componentIris: [rawDimension.iri],
filters: Object.keys(rawFilters).length > 0 ? rawFilters : undefined,
loadValues: true,
};
}),
},
});

const dimension = data?.dataCubesComponents?.dimensions?.[0] ?? rawDimension;
const controls = dimension.isKeyDimension ? null : (
<Box sx={{ display: "flex", flexGrow: 1 }}>
<IconButton
Expand All @@ -120,8 +147,9 @@ const DataFilterSelectGeneric = (props: DataFilterSelectGenericProps) => {
),
controls,
id: `select-single-filter-${index}`,
disabled,
disabled: fetching || disabled,
isOptional: !dimension.isKeyDimension,
loading: fetching,
};

if (
Expand Down Expand Up @@ -297,6 +325,7 @@ const useFilterReorder = ({
iri: cube.iri,
filters: undefined,
joinBy: cube.joinBy,
loadValues: true,
};
});

Expand Down Expand Up @@ -704,7 +733,10 @@ export const ChartConfigurator = ({
</div>
<DataFilterSelectGeneric
key={dimension.iri}
dimension={dimension}
rawDimension={dimension}
filterDimensionIris={filterDimensions
.slice(0, i)
.map((d) => d.iri)}
index={i}
disabled={fetching}
onRemove={() =>
Expand Down
1 change: 1 addition & 0 deletions app/configurator/components/chart-options-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const ChartOptionsSelector = ({
cubeFilters: chartConfig.cubes.map((cube) => ({
iri: cube.iri,
joinBy: cube.joinBy,
loadValues: true,
})),
},
});
Expand Down
1 change: 1 addition & 0 deletions app/configurator/components/chart-type-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const ChartTypeSelector = (props: ChartTypeSelectorProps) => {
cubeFilters: chartConfig.cubes.map((cube) => ({
iri: cube.iri,
joinBy: cube.joinBy,
loadValues: true,
})),
},
});
Expand Down
2 changes: 1 addition & 1 deletion app/configurator/components/field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export const DataFilterSelect = ({

const canUseMostRecentValue = isTemporalOrdinalDimension(dimension);
const usesMostRecentValue = isDynamicMaxValue(fieldProps.value);
const maxValue = sortedValues[sortedValues.length - 1].value;
const maxValue = sortedValues[sortedValues.length - 1]?.value;

return (
<Select
Expand Down
38 changes: 23 additions & 15 deletions app/configurator/configurator-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import setWith from "lodash/setWith";
import sortBy from "lodash/sortBy";
import unset from "lodash/unset";
import { NextRouter, useRouter } from "next/router";
import { createContext, Dispatch, useContext, useEffect, useMemo } from "react";
import { Dispatch, createContext, useContext, useEffect, useMemo } from "react";
import { Reducer, useImmerReducer } from "use-immer";

import {
Expand Down Expand Up @@ -34,20 +34,20 @@ import {
ConfiguratorStatePublishing,
ConfiguratorStateSelectingDataSet,
DataSource,
decodeConfiguratorState,
enableLayouting,
Filters,
FilterValue,
Filters,
GenericField,
GenericFields,
getChartConfig,
getChartConfigFilters,
ImputationType,
InteractiveFiltersConfig,
Layout,
decodeConfiguratorState,
enableLayouting,
getChartConfig,
getChartConfigFilters,
isAreaConfig,
isColorFieldInConfig,
isTableConfig,
Layout,
makeMultiFilter,
} from "@/config-types";
import { mapValueIrisToColor } from "@/configurator/components/ui-helpers";
Expand All @@ -59,9 +59,9 @@ import {
DataCubeComponents,
Dimension,
DimensionValue,
ObservationValue,
isGeoDimension,
isMeasure,
ObservationValue,
} from "@/domain/data";
import { DEFAULT_DATA_SOURCE } from "@/domain/datasource";
import { client } from "@/graphql/client";
Expand Down Expand Up @@ -359,7 +359,12 @@ const getCachedComponents = (
sourceType: draft.dataSource.type,
sourceUrl: draft.dataSource.url,
locale,
cubeFilter: { iri: cubeFilter.iri, joinBy: cubeFilter.joinBy },
cubeFilter: {
bprusinowski marked this conversation as resolved.
Show resolved Hide resolved
iri: cubeFilter.iri,
componentIris: undefined,
joinBy: cubeFilter.joinBy,
loadValues: true,
},
})!;
});

Expand Down Expand Up @@ -613,11 +618,14 @@ export const applyNonTableDimensionToFilters = ({
: undefined;
const filterValue = hierarchyTopMost
? hierarchyTopMost.value
: dimension.values[0].value;
filters[dimension.iri] = {
type: "single",
value: filterValue,
};
: dimension.values[0]?.value;

if (filterValue) {
filters[dimension.iri] = {
type: "single",
value: filterValue,
};
}
}
};

Expand Down Expand Up @@ -1482,7 +1490,7 @@ export const initChartStateFromCube = async (
sourceType: dataSource.type,
sourceUrl: dataSource.url,
locale,
cubeFilters: [{ iri: cubeIri }],
cubeFilters: [{ iri: cubeIri, loadValues: true }],
});

if (components?.dataCubesComponents) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const InteractiveFiltersConfigurator = ({
cubeFilters: chartConfig.cubes.map((cube) => ({
iri: cube.iri,
joinBy: cube.joinBy,
loadValues: true,
})),
},
});
Expand Down
1 change: 1 addition & 0 deletions app/configurator/table/table-chart-configurator.hook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const useTableChartController = (
cubeFilters: chartConfig.cubes.map((cube) => ({
iri: cube.iri,
joinBy: cube.joinBy,
loadValues: true,
})),
},
});
Expand Down
1 change: 1 addition & 0 deletions app/graphql/query-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export type DataCubeComponentFilter = {
filters?: Maybe<Scalars['Filters']>;
componentIris?: Maybe<Array<Scalars['String']>>;
joinBy?: Maybe<Scalars['String']>;
loadValues?: Maybe<Scalars['Boolean']>;
};


Expand Down
1 change: 1 addition & 0 deletions app/graphql/resolver-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export type DataCubeComponentFilter = {
filters?: Maybe<Scalars['Filters']>;
componentIris?: Maybe<Array<Scalars['String']>>;
joinBy?: Maybe<Scalars['String']>;
loadValues?: Maybe<Scalars['Boolean']>;
};


Expand Down
8 changes: 4 additions & 4 deletions app/graphql/resolvers/rdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export const dataCubeComponents: NonNullable<
const { loaders, sparqlClient, sparqlClientStream, cache } = await setup(
info
);
const { iri, latest = true, componentIris, filters } = cubeFilter;
const { iri, latest = true, componentIris, filters, loadValues } = cubeFilter;
const rawCube = await loaders.cube.load(iri);

if (!rawCube) {
Expand Down Expand Up @@ -183,9 +183,9 @@ export const dataCubeComponents: NonNullable<
cache,
filters
);
const values: DimensionValue[] = await dimensionValuesLoader.load(
component
);
const values: DimensionValue[] = loadValues
? await dimensionValuesLoader.load(component)
: [];
values.sort((a, b) =>
ascending(
a.position ?? a.value ?? undefined,
Expand Down
1 change: 1 addition & 0 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ input DataCubeComponentFilter {
filters: Filters
componentIris: [String!]
joinBy: String
loadValues: Boolean
}

input DataCubeMetadataFilter {
Expand Down
Loading
Loading