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: Only load key dimension and measure values during chart initialization #1890

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ You can also check the
same iri that come from different cubes (when merging cubes)
- Map legend is now correctly updated (in some cases it was rendered
incorrectly on the initial render)
- Performance
- We no longer load non-key dimensions when initializing a chart
- Maintenance
- Added a way to do local visual regression testing of charts between
different branches
Expand Down
1 change: 1 addition & 0 deletions app/configurator/configurator-state/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Object.assign(mockClient, {
query: jest.fn().mockImplementation(() => ({
toPromise: jest.fn().mockResolvedValue({
data: {
dataCubePreview: getCachedComponentsMock.geoAndNumerical,
possibleFilters,
},
}),
Expand Down
34 changes: 33 additions & 1 deletion app/configurator/configurator-state/init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import {
import { SELECTING_DATASET_STATE } from "@/configurator/configurator-state/initial";
import { executeDataCubesComponentsQuery } from "@/graphql/hooks";
import {
DataCubePreviewDocument,
DataCubePreviewQuery,
DataCubePreviewQueryVariables,
PossibleFiltersDocument,
PossibleFiltersQuery,
PossibleFiltersQueryVariables,
Expand Down Expand Up @@ -44,11 +47,40 @@ export const initChartStateFromCube = async (
dataSource,
});

const { data: dataCubePreview } = await client
.query<DataCubePreviewQuery, DataCubePreviewQueryVariables>(
DataCubePreviewDocument,
{
sourceType: dataSource.type,
sourceUrl: dataSource.url,
locale,
cubeFilter: { iri: cubeIri },
}
)
.toPromise();

const previewDimensions = dataCubePreview?.dataCubePreview.dimensions ?? [];
const previewMeasures = dataCubePreview?.dataCubePreview.measures ?? [];
const componentIds = previewDimensions.some((d) => !d.isKeyDimension)
? [
...previewDimensions.filter((d) => d.isKeyDimension).map((d) => d.id),
...previewMeasures.map((d) => d.id),
]
: // As the query with undefined component ids is also used in other parts of the app,
// we want to benefit from the cache and not refetch the data if we already have it.
undefined;

const { data: components } = await executeDataCubesComponentsQuery(client, {
sourceType: dataSource.type,
sourceUrl: dataSource.url,
locale,
cubeFilters: [{ iri: latestCubeIri, loadValues: true }],
cubeFilters: [
{
iri: latestCubeIri,
componentIds,
loadValues: true,
},
],
});

if (!components?.dataCubesComponents) {
Expand Down
Loading