Skip to content

Commit

Permalink
Merge pull request #1890 from visualize-admin/perf/do-not-fetch-non-k…
Browse files Browse the repository at this point in the history
…ey-dimensions

perf: Only load key dimension and measure values during chart initialization
  • Loading branch information
bprusinowski authored Nov 20, 2024
2 parents 9081202 + 0aec80d commit ab6cf2c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
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

0 comments on commit ab6cf2c

Please sign in to comment.