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 5 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
2 changes: 1 addition & 1 deletion app/charts/shared/chart-data-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ 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
},
],
// 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
23 changes: 2 additions & 21 deletions app/components/chart-filters-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import {
isTemporalOrdinalDimension,
} from "@/domain/data";
import { useTimeFormatUnit } from "@/formatters";
import { useDataCubesComponentsQuery } from "@/graphql/hooks";
import { useLocale } from "@/locales/use-locale";
import { useInteractiveFilters } from "@/stores/interactive-filters";

type ChartFiltersListProps = {
Expand All @@ -33,8 +31,7 @@ type ChartFiltersListProps = {
};

export const ChartFiltersList = (props: ChartFiltersListProps) => {
const { dataSource, chartConfig, dimensions, measures } = props;
const locale = useLocale();
const { chartConfig, dimensions, measures } = props;
const timeFormatUnit = useTimeFormatUnit();
const timeSlider = useInteractiveFilters((d) => d.timeSlider);
const animationField = getAnimationField(chartConfig);
Expand All @@ -44,23 +41,8 @@ export const ChartFiltersList = (props: ChartFiltersListProps) => {
measures,
componentIris: extractChartConfigComponentIris(chartConfig),
});
const [{ data }] = useDataCubesComponentsQuery({
variables: {
sourceType: dataSource.type,
sourceUrl: dataSource.url,
locale,
cubeFilters:
filters?.map((filter) => ({
iri: filter.iri,
componentIris: filter.componentIris,
filters: filter.filters,
joinBy: filter.joinBy,
})) ?? [],
},
pause: !filters,
});
const allFilters = React.useMemo(() => {
if (!data?.dataCubesComponents || !filters || !dimensions || !measures) {
if (!filters || !dimensions || !measures) {
return [];
}

Expand Down Expand Up @@ -132,7 +114,6 @@ export const ChartFiltersList = (props: ChartFiltersListProps) => {
return namedFilters;
});
}, [
data?.dataCubesComponents,
dimensions,
measures,
filters,
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
22 changes: 13 additions & 9 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,11 @@ 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,
joinBy: cubeFilter.joinBy,
loadValues: true,
},
})!;
});

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
6 changes: 4 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"@next/mdx": "^11.0.1",
"@preconstruct/next": "^3.0.1",
"@prisma/client": "^4.5.0",
"@rdfjs/namespace": "^1.1.0",
"@rdfjs/data-model": "^2.0.2",
"@rdfjs/namespace": "^2.0.1",
"@reach/auto-id": "^0.15.0",
"@sentry/nextjs": "^7.7.0",
"@tpluscode/rdf-ns-builders": "2.0.1",
Expand Down Expand Up @@ -169,7 +170,8 @@
"@types/qs": "^6.9.8",
"@types/rdf-ext": "^1.3.8",
"@types/rdf-js": "^4.0.1",
"@types/rdfjs__namespace": "^1.1.3",
"@types/rdfjs__data-model": "^2.0.7",
"@types/rdfjs__namespace": "^2.0.10",
"@types/react-beautiful-dnd": "^13.1.4",
"@types/react-table": "^7.7.15",
"@types/react-window": "^1.8.2",
Expand Down
Loading