Skip to content

Commit

Permalink
perf: Add a way to disable values and hierarchies loading in DataCube…
Browse files Browse the repository at this point in the history
…Components
  • Loading branch information
bprusinowski committed Dec 15, 2023
1 parent ea35ade commit db51fda
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
5 changes: 4 additions & 1 deletion app/browser/dataset-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ export const DataSetPreview = ({
sourceType: dataSource.type,
sourceUrl: dataSource.url,
locale,
cubeFilters,
cubeFilters: cubeFilters.map((filter) => ({
...filter,
disableValuesLoad: true,
})),
},
});
const classes = useStyles({
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 @@ -99,6 +99,7 @@ export type DataCubeComponentFilter = {
filters?: Maybe<Scalars['Filters']>;
componentIris?: Maybe<Array<Scalars['String']>>;
joinBy?: Maybe<Scalars['String']>;
disableValuesLoad?: 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 @@ -100,6 +100,7 @@ export type DataCubeComponentFilter = {
filters?: Maybe<Scalars['Filters']>;
componentIris?: Maybe<Array<Scalars['String']>>;
joinBy?: Maybe<Scalars['String']>;
disableValuesLoad?: Maybe<Scalars['Boolean']>;
};


Expand Down
46 changes: 29 additions & 17 deletions app/graphql/resolvers/rdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,13 @@ 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,
disableValuesLoad,
} = cubeFilter;
const rawCube = await loaders.cube.load(iri);

if (!rawCube) {
Expand All @@ -176,21 +182,27 @@ export const dataCubeComponents: NonNullable<
await Promise.all(
rawComponents.map(async (component) => {
const { data } = component;
const dimensionValuesLoader = getDimensionValuesLoader(
sparqlClient,
loaders,
cache,
filters
);
const values: DimensionValue[] = await dimensionValuesLoader.load(
component
);
values.sort((a, b) =>
ascending(
a.position ?? a.value ?? undefined,
b.position ?? b.value ?? undefined
)
);

let values: DimensionValue[] = [];

if (!disableValuesLoad) {
const dimensionValuesLoader = getDimensionValuesLoader(
sparqlClient,
loaders,
cache,
filters
);
const values: DimensionValue[] = await dimensionValuesLoader.load(
component
);
values.sort((a, b) =>
ascending(
a.position ?? a.value ?? undefined,
b.position ?? b.value ?? undefined
)
);
}

const baseComponent: BaseComponent = {
// We need to use original iri here, as the cube iri might have changed.
cubeIri: iri,
Expand Down Expand Up @@ -220,7 +232,7 @@ export const dataCubeComponents: NonNullable<
measures.push(result);
} else {
const dimensionType = resolveDimensionType(component);
const hierarchy = true // TODO: make this configurable
const hierarchy = !disableValuesLoad
? await queryHierarchy(
component,
locale,
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
disableValuesLoad: Boolean
}

input DataCubeMetadataFilter {
Expand Down

0 comments on commit db51fda

Please sign in to comment.